Skip to content

Commit

Permalink
fix merged apks for building module
Browse files Browse the repository at this point in the history
  • Loading branch information
j-hc committed Sep 1, 2024
1 parent 1792aa3 commit a8ddca3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 25 additions & 10 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a8ddca3

Please sign in to comment.