Skip to content

Commit a8ddca3

Browse files
committed
fix merged apks for building module
1 parent 1792aa3 commit a8ddca3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44
shopt -s nullglob
5-
trap "rm -rf temp/*tmp.* temp/*/*tmp.*; exit 130" INT
5+
trap "rm -rf temp/*tmp.* temp/*/*tmp.* temp/*-temporary-files; exit 130" INT
66

77
if [ "${1-}" = "clean" ]; then
88
rm -rf temp build logs build.md

utils.sh

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,26 @@ isoneof() {
201201
return 1
202202
}
203203

204+
merge_splits() {
205+
local bundle=$1 output=$2
206+
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
207+
if ! OP=$(java -jar "$TEMP_DIR/apkeditor.jar" merge -i "${bundle}" -o "${bundle}.mzip" -clean-meta -f 2>&1); then
208+
epr "$OP"
209+
return 1
210+
fi
211+
# this is required because of apksig
212+
mkdir "${bundle}-zip"
213+
unzip -qo "${bundle}.mzip" -d "${bundle}-zip"
214+
cd "${bundle}-zip" || abort
215+
zip -0rq "../../${bundle}.zip" .
216+
cd ../.. || abort
217+
pr "Merging splits"
218+
patch_apk "${bundle}.zip" "${output}" "--exclusive" "${args[cli]}" "${args[ptjar]}"
219+
local ret=$?
220+
rm -r "${bundle}-zip" "${bundle}.zip" "${bundle}.mzip" || :
221+
return $ret
222+
}
223+
204224
# -------------------- apkmirror --------------------
205225
apk_mirror_search() {
206226
local resp="$1" dpi="$2" arch="$3" apk_bundle="$4"
@@ -240,15 +260,8 @@ dl_apkmirror() {
240260
url=$(echo "$resp" | $HTMLQ --base https://www.apkmirror.com --attribute href "a.btn") || return 1
241261
url=$(req "$url" - | $HTMLQ --base https://www.apkmirror.com --attribute href "span > a[rel = nofollow]") || return 1
242262
if [ "$is_bundle" = true ]; then
243-
gh_dl "$TEMP_DIR/apkeditor.jar" "https://github.com/REAndroid/APKEditor/releases/latest/download/APKEditor-1.3.9.jar" >/dev/null || return 1
244263
req "$url" "${output}.apkm"
245-
java -jar "$TEMP_DIR/apkeditor.jar" merge -i "${output}.apkm" -o "${output}.zip" -clean-meta -f || return 1
246-
mkdir "${output}-zip" || :
247-
unzip -qo "${output}.zip" -d "${output}-zip"
248-
cd "${output}-zip" || abort
249-
zip -FS0rq "../../${output}" .
250-
cd ../.. || abort
251-
rm -r "${output}-zip" "${output}.apkm" "${output}.zip"
264+
merge_splits "${output}.apkm" "${output}"
252265
else
253266
req "$url" "${output}"
254267
fi
@@ -334,8 +347,10 @@ patch_apk() {
334347
--keystore-entry-password=123456789 --keystore-password=123456789 --signer=jhc --keystore-entry-alias=jhc --options=options.json"
335348
if [ "$OS" = Android ]; then cmd+=" --custom-aapt2-binary=${AAPT2}"; fi
336349
pr "$cmd"
337-
eval "$cmd"
338-
[ -f "$patched_apk" ]
350+
if eval "$cmd"; then [ -f "$patched_apk" ]; else
351+
rm "$patched_apk" 2>/dev/null || :
352+
return 1
353+
fi
339354
}
340355

341356
check_sig() {

0 commit comments

Comments
 (0)