• Tutorial: Real world testing installing & backing up Android APKs 100%

    From Wally J@21:1/5 to All on Sat Nov 4 14:16:22 2023
    XPost: comp.mobile.android, comp.sys.mac.system, alt.os.linux
    XPost: alt.comp.freeware

    Tutorial: Real world testing installing & backing up Android APKs
    100% from Windows over adb on USB (Mac/Linux is the same)

    Most people are perhaps not aware that Android, unlike other OS's
    _always_
    saves "an installer" APK (even for pre-installed system apps).

    This always-saved APK is why (and how) "Apk extractors" can work.
    <https://play.google.com/store/search?q=apk%20extractor&c=apps>

    But...

    I always wondered if the apk that you download is exactly the same as the
    apk that is always saved - as what's saved could be hardware specific.
    <https://duckduckgo.com/?&q=apex+versus+apk+hardware+specific>

    That is, Android could choose to save a "base" APK stripped of everything needed other than what's specifically needed for _your_ specific hardware.

    Or not...

    So I ran a test of that just now, arbitrarily choosing OSMAnd to test.
    This was all done from Windows (using my scrcpy mirrored Android device).
    *But all these commands are _exactly_ the same on the Mac & on Linux.*

    0. Long ago I had installed & set up the software used in this tutorial:
    Windows/Linux/Mac free open source Android mirroring software:
    <https://scrcpy.org/>
    Windows/Linux/Mac free open source Android adb bridge software:
    <https://www.xda-developers.com/install-adb-windows-macos-linux/>

    1. On the Android display, I checked my current OSMAnd~ version:
    OSMAnd~ > Hamburger (at bottom left) > Help > About === OsmAnd~ 3.5.5

    2. On Windows, I ascertained the Android 13 OSMAnd package name:
    C:\> adb shell pm list packages -3 | findstr /i "osmand"
    Result:
    package:net.osmand.plus

    3. On Windows, I determined the Android path to that user-installed OSMAnd:
    C:\> adb shell pm path net.osmand.plus
    Result:
    package:/data/app/~~Eqsny-D-ckbe9so7Cn4d6A==/net.osmand.plus-u9B30YyDqBAbCim5higUIA==/base.apk

    4. On Windows, I copied that package from Android over to Windows:
    C:\> adb pull /data/app/~~Eqsny-D-ckbe9so7Cn4d6A==/net.osmand.plus-u9B30YyDqBAbCim5higUIA==/base.apk
    Result:
    /data/app/~~Eqsny-D-ckbe9so7Cn4d6A==/net.osmand.plus-u9B30YyDqBAbCim5higUIA==/base.apk: 1 file pulled, 0 skipped. 28.6 MB/s (111158599 bytes in 3.710s)

    5. On Windows, I renamed that base apk package for the later comparison:
    C:\> dir *.apk
    Result:
    11/04/2023 12:26 PM 111,158,599 base.apk
    C:\> move base.apk base_net.osmand.plus_v3.5.5.apk
    Result:
    1 file(s) moved.

    6. On Windows, I downloaded the latest OSMAnd~ version from F-Droid:
    C:\> wget https://f-droid.org/repo/net.osmand.plus_451003.apk
    Result:
    wget https://f-droid.org/repo/net.osmand.plus_451003.apk
    --2023-11-04 12:40:11-- https://f-droid.org/repo/net.osmand.plus_451003.apk
    Resolving f-droid.org (f-droid.org)... 136.243.44.143, 65.21.79.229
    Connecting to f-droid.org (f-droid.org)|136.243.44.143|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 146644539 (140M) [application/vnd.android.package-archive]
    Saving to: 'net.osmand.plus_451003.apk'
    net.osmand.plus_451003.apk 100%[=================================================>] 139.85M 1.29MB/s in 1m 40s
    2023-11-04 12:41:52 (1.40 MB/s) - 'net.osmand.plus_451003.apk' saved [146644539/146644539]

    7. On Windows, I installed/updated that OSMAnd~ version on Android:
    C:\> adb install -r net.osmand.plus_451003.apk
    Result:
    Performing Streamed Install
    Success

    8. On Windows, I renamed that original OSMAnd~ apk file
    C:\> move net.osmand.plus_451003.apk orig_net.osmand.plus_451003.apk

    9. On the Windows Android display, I checked the new OSMAnd~ version
    When I started OSMAnd~, this popped up: "What's New in 4.5.10"
    Result:
    OSMAnd~ > Hamburger (at bottom left) > Help > About === OsmAnd~ 4.5.10

    10. On Windows, I determined the Android path to that user-installed package
    C:\> adb shell pm path net.osmand.plus
    Result:
    package:/data/app/~~k-jK7n2qHWcW_giNy6oVEA==/net.osmand.plus-6ws8wQWIkEi8vVgL5q3EdA==/base.apk
    Note that this is a different path than the prior version was.

    11. On Windows, I copied that package from Android back to Windows
    C:\> adb pull /data/app/~~k-jK7n2qHWcW_giNy6oVEA==/net.osmand.plus-6ws8wQWIkEi8vVgL5q3EdA==/base.apk
    Result:
    /data/app/~~k-jK7n2qHWcW_giNy6oVEA==/net.osmand.plus-6ws8wQWIkEi8vVgL5q3EdA==/base.apk: 1 file pulled, 0 skipped. 30.0 MB/s (146644539 bytes in 4.667s)

    12. On Windows, I renamed that base apk package for later comparison.
    C:\> dir *.apk
    Result:
    11/04/2023 01:20 PM 146,644,539 base.apk
    C:\> move base.apk base_net.osmand.plus_v4.5.10.apk
    Result:
    1 file(s) moved.

    13. On Windows, I checked the three APK file sizes for comparison:
    C:\> dir *net.osmand.plus*
    Result:
    11/04/2023 12:26 PM 111,158,599 base_net.osmand.plus_v3.5.5.apk
    11/04/2023 01:20 PM 146,644,539 base_net.osmand.plus_v4.5.10.apk
    09/12/2023 12:13 AM 146,644,539 orig_net.osmand.plus_451003.apk

    14. Just to be sure they're the same, on Windows, I ran a comparative hash:
    C:\> for /F %i in ('dir /b *.apk') do certutil -hashfile %i SHA256
    Result:
    SHA256 hash of base_net.osmand.plus_v3.5.5.apk:
    40b79290d64302c6623bfcf8c99ab0a7dd2c5bda16172ed2a90ced8019f3704e
    CertUtil: -hashfile command completed successfully.

    SHA256 hash of net.osmand.plus_451003.apk:
    4a7e3b777e08a6fa039cb2367073ea00d92d80058e728fcd8285e3f714e88777
    CertUtil: -hashfile command completed successfully.

    SHA256 hash of base_net.osmand.plus_v4.5.10.apk:
    4a7e3b777e08a6fa039cb2367073ea00d92d80058e728fcd8285e3f714e88777
    CertUtil: -hashfile command completed successfully.

    Interesting. I'm surprised. But I probably shouldn't have been surprised.

    I had expected the base apk to be _smaller_ than the original APK
    (because I had assumed hardware-specific base APKs are saved on Android).

    But in this single test (notice we're not using the new APEX files!),
    what was (always automatically) saved on Android as the base.apk
    turned out to be exactly the same as what was downloaded and installed.

    As always, this is sent to auto-archived newsgroups for leverage
    to many others now & in the future, even those not on Usenet.

    The f'up though is set to just the Android & Windows newsgroups.
    As always, if you know more than I do, please expand our tribal knowledge.
    --
    The whole point of Usenet is to find people who know more than you do.
    And to contribute to the overall tribal knowledge value of the newsgroup.
    It's a domino effect where each of us helps the next person in the lineup.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)