From a8ddca39a4351fc38993a88e7dea08df7dc4cc48 Mon Sep 17 00:00:00 2001 From: j-hc Date: Sun, 1 Sep 2024 15:28:50 +0300 Subject: [PATCH] fix merged apks for building module --- build.sh | 2 +- utils.sh | 35 +++++++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/build.sh b/build.sh index 7f67488b15..e76388408e 100755 --- a/build.sh +++ b/build.sh @@ -2,7 +2,7 @@ set -euo pipefail shopt -s nullglob -trap "rm -rf temp/*tmp.* temp/*/*tmp.*; exit 130" INT +trap "rm -rf temp/*tmp.* temp/*/*tmp.* temp/*-temporary-files; exit 130" INT if [ "${1-}" = "clean" ]; then rm -rf temp build logs build.md diff --git a/utils.sh b/utils.sh index 3682507974..eb0b938244 100755 --- a/utils.sh +++ b/utils.sh @@ -201,6 +201,26 @@ isoneof() { return 1 } +merge_splits() { + local bundle=$1 output=$2 + gh_dl "$TEMP_DIR/apkeditor.jar" "https://github.com/REAndroid/APKEditor/releases/download/V1.3.9/APKEditor-1.3.9.jar" >/dev/null || return 1 + if ! OP=$(java -jar "$TEMP_DIR/apkeditor.jar" merge -i "${bundle}" -o "${bundle}.mzip" -clean-meta -f 2>&1); then + epr "$OP" + return 1 + fi + # this is required because of apksig + mkdir "${bundle}-zip" + unzip -qo "${bundle}.mzip" -d "${bundle}-zip" + cd "${bundle}-zip" || abort + zip -0rq "../../${bundle}.zip" . + cd ../.. || abort + pr "Merging splits" + patch_apk "${bundle}.zip" "${output}" "--exclusive" "${args[cli]}" "${args[ptjar]}" + local ret=$? + rm -r "${bundle}-zip" "${bundle}.zip" "${bundle}.mzip" || : + return $ret +} + # -------------------- apkmirror -------------------- apk_mirror_search() { local resp="$1" dpi="$2" arch="$3" apk_bundle="$4" @@ -240,15 +260,8 @@ dl_apkmirror() { url=$(echo "$resp" | $HTMLQ --base https://www.apkmirror.com --attribute href "a.btn") || return 1 url=$(req "$url" - | $HTMLQ --base https://www.apkmirror.com --attribute href "span > a[rel = nofollow]") || return 1 if [ "$is_bundle" = true ]; then - gh_dl "$TEMP_DIR/apkeditor.jar" "https://github.com/REAndroid/APKEditor/releases/latest/download/APKEditor-1.3.9.jar" >/dev/null || return 1 req "$url" "${output}.apkm" - java -jar "$TEMP_DIR/apkeditor.jar" merge -i "${output}.apkm" -o "${output}.zip" -clean-meta -f || return 1 - mkdir "${output}-zip" || : - unzip -qo "${output}.zip" -d "${output}-zip" - cd "${output}-zip" || abort - zip -FS0rq "../../${output}" . - cd ../.. || abort - rm -r "${output}-zip" "${output}.apkm" "${output}.zip" + merge_splits "${output}.apkm" "${output}" else req "$url" "${output}" fi @@ -334,8 +347,10 @@ patch_apk() { --keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc --options=options.json" if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${AAPT2}"; fi pr "$cmd" - eval "$cmd" - [ -f "$patched_apk" ] + if eval "$cmd"; then [ -f "$patched_apk" ]; else + rm "$patched_apk" 2>/dev/null || : + return 1 + fi } check_sig() {