Targeting R+ (version 30 and above) requires the resources.arsc of installed APKs to be stored uncompressed and aligned on a 4-byte boundary

Viewed 7479

I am trying to update android target API from 29 to 30. I have updated:

compileSdkVersion           = 30
targetSdkVersion            = 30
buildToolsVersion           = "30.0.2"

The app is aligned with zipalign -p -f -v 4 before signing as per the official documentation.

When I try to adb install the .apk however I get:

Failure [-124: Failed parse during installPackageLI: Targeting R+ (version 30 and above) requires the resources.arsc of installed APKs to be stored uncompressed and aligned on a 4-byte boundary]

Has anyone had any success with that?

2 Answers

I had a similar issue.

Observe the zipalign logs for this - enter image description here

It should not be compressed. If it is, then that is the issue. Somehow you need to make it not compressed. It should look like

resources.arsc (OK)

Give this a try -

unzip -q -o ur-apk.apk -d ur-unzipped-apk-folder
cd ur-unziped-apk-folder
zip -n "resources.arsc" -qr ../zipped.apk *

Use this zipped.apk for alignment and signing as per the official doc.

Note - Apps that target Android 11 (API level 30) or higher can't be installed if they contain a compressed resources.arsc file or if this file is not aligned on a 4-byte boundary

https://developer.android.com/about/versions/11/behavior-changes-11#app-packaging https://developer.android.com/studio/build/building-cmdline#sign_cmdline

If you zipalign and then sign with an old version of jarsigner then it will unalign during the signing!

Be sure to use the newer apksigner. On my system it is in ~/Android/Sdk/build-tools/32.0.0/apksigner

Here is my repack-n-sign script. Note that you may need to update your BUILD_TOOLS path and set it to the right location:

#!/bin/sh

BUILD_TOOLS=~/Android/Sdk/build-tools/32.0.0/

if [ -z "$1" ]; then
        echo "usage: $0 your-app.apk"
        exit 1
fi

DIR=`mktemp -d`
DN=`dirname "$1"`
BN=`basename "$1"`
OUT="$DN/repacked-$BN"
OUT_ALIGNED="$DN/aligned-$BN"
OUT_SIGNED="$DN/signed-$BN"

# Debug mode
set -x

# Repack without the META-INF in case it was already signed
# and flag resources.arsc as no-compress:
unzip -q "$1" -d "$DIR"
pushd .
cd $DIR

rm -rf "$DIR/META-INF"
zip -n "resources.arsc" -r ../repacked.$$.apk *

popd

mv "$DIR/../repacked.$$.apk" "$OUT"

# Align
rm -f "$OUT_ALIGNED"
"$BUILD_TOOLS"/zipalign -p -v 4 "$OUT" "$OUT_ALIGNED"

# Verify
"$BUILD_TOOLS"/zipalign -vc 4 "$OUT_ALIGNED"

# Sign
"$BUILD_TOOLS"/apksigner sign -verbose -ks ~/my-release-key.keystore --out "$OUT_SIGNED" "$OUT_ALIGNED"

# Cleanup
rm -rf "$DIR"

echo == Done: $OUT_ALIGNED

Related