Repack and zipalign APKs only with compressed libs and v1 sig

Signed-off-by: Ilya Danilkin <nezorflame@gmail.com>
This commit is contained in:
Ilya Danilkin
2020-07-05 17:53:02 +03:00
committed by Maarten Fonville
parent 6fffe1b34d
commit 6c209510c9
5 changed files with 25 additions and 15 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ ZIPCOMPRESSIONLEVEL="0" # Store only the files in the zip without compressing th
. "$SCRIPTS/inc.sourceshelper.sh" . "$SCRIPTS/inc.sourceshelper.sh"
# Check tools # Check tools
checktools aapt coreutils java jarsigner unzip zip tar realpath zipalign checktools aapt apksigner coreutils java jarsigner unzip zip tar realpath zipalign
case "$API" in case "$API" in
19) PLATFORM="4.4" ;; 19) PLATFORM="4.4" ;;
+13 -10
View File
@@ -326,16 +326,19 @@ buildapk() {
fi fi
install -D "$sourceapk" "$targetapk" install -D "$sourceapk" "$targetapk"
if [ "$API" -lt "23" ] && (unzip -qqql "$targetapk" | grep -q "lib/"); then #only if pre-Marshmallow and the lib folder exists
unzip -Z -1 "$targetapk" | grep "lib/" | grep -v "/crazy." | xargs zip -q -d "$targetapk" #delete all libs, except crazy-linked if (unzip -v "$targetapk" | grep "lib/" | grep -qv "Stored"); then #check if there are compressed libs present
elif [ "$API" -ge "23" ] && (unzip -qqql "$targetapk" | grep -q "lib/"); then #Marshmallow needs (if any exist) libs to be stored without compression within the APK if [ "$API" -lt "23" ]; then #only if pre-Marshmallow
unzip -qqq -o "$targetapk" -d "$targetdir" "lib/*" unzip -Z -1 "$targetapk" | grep "lib/" | grep -v "/crazy." | xargs zip -q -d "$targetapk" #delete all libs, except crazy-linked
zip -q -d "$targetapk" "lib/*" #delete all libs else #Marshmallow and above needs libs to be stored without compression within the APK
CURRENTPWD="$(realpath .)" #if we ever switch to bash, make this a pushd-popd trick unzip -qqq -o "$targetapk" -d "$targetdir" "lib/*"
cd "$targetdir" zip -q -d "$targetapk" "lib/*" #delete all libs
zip -q -r -D -Z store -b "$targetdir" "$targetapk" "lib/" #no parameter for output and mode, we are in 'add and update existing' mode which is default. Lib files have to be stored without compression. CURRENTPWD="$(realpath .)" #if we ever switch to bash, make this a pushd-popd trick
cd "$CURRENTPWD" cd "$targetdir"
rm -rf "$targetdir/lib/" zip -q -r -D -Z store -b "$targetdir" "$targetapk" "lib/" #no parameter for output and mode, we are in 'add and update existing' mode which is default. Lib files have to be stored without compression.
cd "$CURRENTPWD"
rm -rf "$targetdir/lib/"
fi
fi fi
} }
+6
View File
@@ -11,7 +11,13 @@
# GNU General Public License for more details. # GNU General Public License for more details.
# #
alignbuild() { alignbuild() {
echo "Zipaligning APKs..."
for f in $(find "$build" -name '*.apk'); do for f in $(find "$build" -name '*.apk'); do
# skip zipaligning for APKs signed with apksigner, because zipalign strips its signature
# see https://developer.android.com/studio/command-line/zipalign
if timeout 1m apksigner verify --verbose --print-certs "$f" 2>/dev/null | grep -q "(JAR signing): false"; then
continue
fi
mv "$f" "$f.orig" mv "$f" "$f.orig"
zopfli="" zopfli=""
if [ -n "$ZIPALIGNRECOMPRESS" ]; then if [ -n "$ZIPALIGNRECOMPRESS" ]; then
+2 -2
View File
@@ -24,8 +24,8 @@ checktools() {
echo 'Coreutils is required for install, basename, readlink, md5sum and other utilities, but is not installed or found in sh $PATH.';; echo 'Coreutils is required for install, basename, readlink, md5sum and other utilities, but is not installed or found in sh $PATH.';;
jarsigner|keytool) jarsigner|keytool)
echo 'JDK is required for jarsigner and keytools utilities, but is not installed or found in sh $PATH.';; echo 'JDK is required for jarsigner and keytools utilities, but is not installed or found in sh $PATH.';;
aapt|zipalign) aapt|apksigner|zipalign)
echo 'Android SDK is required for aapt and zipalign utilities, but is not installed or found in sh $PATH.';; echo 'Android SDK is required for aapt, apksigner and zipalign utilities, but is not installed or found in sh $PATH.';;
*) *)
echo "$command is required but is not installed.";; echo "$command is required but is not installed.";;
esac esac
+3 -2
View File
@@ -20,12 +20,13 @@ SCRIPTS="$TOP/scripts"
# shellcheck source=scripts/inc.tools.sh # shellcheck source=scripts/inc.tools.sh
. "$SCRIPTS/inc.tools.sh" . "$SCRIPTS/inc.tools.sh"
checktools base64 coreutils unzip checktools apksigner base64 coreutils unzip
for argument in "$@"; do for argument in "$@"; do
file="$(readlink -f "$argument")" file="$(readlink -f "$argument")"
if [ -f "$file" ]; then if [ -f "$file" ]; then
echo "signature of $file:" apksigner verify --verbose --print-certs "$file"
echo "Signature of $file:"
RSAFILE="META-INF/CERT" RSAFILE="META-INF/CERT"
unzip -l "$file" | grep -q "$RSAFILE.RSA" unzip -l "$file" | grep -q "$RSAFILE.RSA"
if [ "$?" != "0" ]; then if [ "$?" != "0" ]; then