DiaKEM / dexcom-g7-apk-patcher

Dexcom G7 .apk patcher | ✅ AAPS Broadcasting ✅ Disable compatibility checks ✅ Enable Screenshots ✅ Decrease required android version
87 stars 30 forks source link

Align ZIP #24

Closed franzs closed 1 year ago

franzs commented 1 year ago

Otherwise it results in an uninstallable APK

% adb install dexcom.patched.apk Performing Streamed Install adb: failed to install dexcom.patched.apk: 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]

franzs commented 1 year ago

It seems to be version dependent: https://developer.android.com/about/versions/11/behavior-changes-11#app-packaging

I'm using Android 12.

Unfortunately I can't test if removing --skipZipAlign will do any harm on Android < 11.

khskekec commented 1 year ago

Hi @franzs,

unfortunately this brings more complexity and introduces new requirements to the local environment. The following is taken from the uber-apk-signer documentation (see here):

Zipalign Executable Zipalign is a tool developed by Google to optimize zips (apks). It is needed if you want to upload it to the Playstore otherwise it is optional. By default this tool will try to zipalign the apk, therefore it will need the location of the executable. If the path isn't passed in the command line interface, the tool checks if it is in PATH environment variable, otherwise it will try to use an embedded version of zipalign. If --skipZipAlign is passed no executable is needed.

Additionally i am not able to reproduce it. adb install unaligned.apk works just fine on Android 12 based emulator.

Bildschirmfoto 2022-11-28 um 21 23 33

I am a bit confused now :(.

Could you please recheck it?

franzs commented 1 year ago

hi @khskekec,

indeed on an android emulator (Android Studio) there are no issues using Android 12 (x86_64). On my OnePlus 8T with LineageOS 19.1 I face these problems though. I have no other devices to test with.

For me the change at https://developer.android.com/about/versions/11/behavior-changes-11#app-packaging is quite clear.

Using ./docker-build.sh needs no additional changes besides removing --skipZipAlign are required.

Signing the apk on my system does not require zipalign to be installed:

% java -jar bin/uber-apk-signer-1.2.1.jar -a dexcom.patched.apk --ks signing.keystore --ksAlias cert --ksPass $KEYSTORE_PASS --ksKeyPass $KEYSTORE_PASS --overwrite
source:
        /home/franz/git/github.com/DiaKEM/dexcom-g7-apk-patcher
zipalign location: BUILT_IN 
        /tmp/uapksigner-8809005954128785996/linux-zipalign-29_0_24349922420449343111.tmp
keystore:
        [0] 174d8fdd /home/franz/git/github.com/DiaKEM/dexcom-g7-apk-patcher/signing.keystore (RELEASE_CUSTOM)

01. dexcom.patched.apk

        SIGN
        file: /home/franz/git/github.com/DiaKEM/dexcom-g7-apk-patcher/dexcom.patched.apk (156.12 MiB)
        checksum: e26c777a0a225e23d59eefd6890736bd5a86582ed48d2d002f08891535a560e8 (sha256)
        - zipalign success
        - sign success

        VERIFY
        file: /home/franz/git/github.com/DiaKEM/dexcom-g7-apk-patcher/dexcom.patched.apk (156.28 MiB)
        checksum: 59befef972641768aada72ffd3b6246ca69fc54c3aeb4ac402ee37fec4049b1e (sha256)
        - zipalign verified
        - signature verified [v3] 
                Subject: CN=Dexcom G7 Hacker, OU=Development, O=Dexcom G7 Hacking Unit, L=Oberhausen, ST=North Rhine-Westphalia, C=DE
                SHA256: 64fd98526c04591081a2385cdba6c480b775e02369caf6b821e086705ebcb2c7 / SHA256withRSA
                Expires: Sun Feb 27 19:37:43 CET 2050

[Mon Nov 28 23:00:31 CET 2022][v1.2.1]
Successfully processed 1 APKs and 0 errors in 4.33 seconds.

There is no zipalign here:

% which zipalign
/usr/bin/which: no zipalign in (/home/franz/.local/bin:/home/franz/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin)

The APK signer states: zipalign location: BUILT_IN

khskekec commented 1 year ago

Hey @franzs,

you are right - had to read more carefully, sry:

If the path isn't passed in the command line interface, the tool checks if it is in PATH environment variable, otherwise it will try to use an embedded version of zipalign.

Let us try to integrate this and see what will happen :).

Thank you for your detailed explanation 👍 .

andrew-warrington commented 1 year ago

Thanks for this software @khskekec -- just what I needed. And thanks for this PR @franzs.

I was getting the same error on Xiaomi Poco F3 running Miui 13.0.9 stable (Android 12). This PR is what fixed it for me.

khskekec commented 1 year ago

Reintegrated it correctly without unnecessary changes!