outline-apps icon indicating copy to clipboard operation
outline-apps copied to clipboard

Support 16KB memory page sizes on android

Open ohnorobo opened this issue 3 months ago • 3 comments

Application: Outline Client

We've done some previous work to support 16KB page sizes on android, but it looks like we need to do more.

Latest release candidate (1.19.0 app store) says:

Does not support 16 KB Learn more Uncompressed native libraries are not zip aligned for 16 KB within your app. To resolve this, fix your AGP configuration.

Libraries that do not support 16 KB: lib/arm64-v8a/libsentry-android.so lib/arm64-v8a/libsentry.so lib/x86_64/libsentry-android.so lib/x86_64/libsentry.so

ohnorobo avatar Dec 11 '25 14:12 ohnorobo

previous work: https://github.com/Jigsaw-Code/outline-apps/pull/2621

ohnorobo avatar Dec 11 '25 14:12 ohnorobo

Script for checking elf alignment: https://android.googlesource.com/platform/system/extras/+/master/tools/check_elf_alignment.sh?pli=1

Output:

npm run action client/src/cordova/build android
./check_elf_alignment.sh client/platforms/android/app/build/outputs/apk/debug/app-debug.apk

Recursively analyzing client/platforms/android/app/build/outputs/apk/debug/app-debug.apk

NOTICE: Zip alignment check requires build-tools version 35.0.0-rc3 or higher.
  You can install the latest build-tools by running the below command
  and updating your $PATH:

    sdkmanager "build-tools;35.0.0-rc3"

=== ELF alignment ===
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/armeabi-v7a/libsentry.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/armeabi-v7a/libgojni.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/armeabi-v7a/libsentry-android.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/x86/libsentry.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/x86/libgojni.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/x86/libsentry-android.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/arm64-v8a/libsentry.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/arm64-v8a/libgojni.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/arm64-v8a/libsentry-android.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/x86_64/libsentry.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/x86_64/libgojni.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/app-debug_out_XXXXX.tPhVFudOo4/lib/x86_64/libsentry-android.so: \e[31mUNALIGNED\e[0m (2**12)
\e[31mFound 10 unaligned libs (only arm64-v8a/x86_64 libs need to be aligned).\e[0m
=====================

ohnorobo avatar Dec 11 '25 17:12 ohnorobo

We need to upgrade to a more recent Sentry version. Looks like we are using 2.0.2: https://github.com/Jigsaw-Code/outline-apps/blob/ceea7830a40bf7a4c78a7c46c4baa2c57e55b890/client/src/cordova/plugin/android/build-extras.gradle#L30

Current version is 8.28.0.

I'd feed the migration guide into AI and ask for it to upgrade the code

fortuna avatar Dec 12 '25 02:12 fortuna

I'm still getting the error

Your app does not support 16 KB memory page sizes. [Learn More](https://developer.android.com/guide/practices/page-sizes)

in the latest android candidate

Although there are no specific .so file errors

ohnorobo avatar Dec 16 '25 14:12 ohnorobo

Following these bundletool instructions to check additional sources of error.

SENTRY_DSN=<sentry info> npm run action client/src/cordova/build android -- --buildMode=release --versionName=1.19.0
java -jar bundletool.jar dump config --bundle=client/platforms/android/app/build/outputs/bundle/release/app-release.aab
{
  "bundletool": {
    "version": "1.17.1"
  },
  "optimizations": {
    "splitsConfig": {
    },
    "uncompressNativeLibraries": {
      "enabled": true
    },
    "storeArchive": {
      "enabled": true
    }
  },
  "compression": {
    "uncompressedGlob": ["**.3[gG]2", "**.3[gG][pP]", "**.3[gG][pP][pP]", "**.3[gG][pP][pP]2", "**.[aA][aA][cC]", "**.[aA][mM][rR]", "**.[aA][wW][bB]", "**.[gG][iI][fF]", "**.[iI][mM][yY]", "**.[jJ][eE][tT]", "**.[jJ][pP][eE][gG]", "**.[jJ][pP][gG]", "**.[mM]4[aA]", "**.[mM]4[vV]", "**.[mM][iI][dD]", "**.[mM][iI][dD][iI]", "**.[mM][kK][vV]", "**.[mM][pP]2", "**.[mM][pP]3", "**.[mM][pP]4", "**.[mM][pP][eE][gG]", "**.[mM][pP][gG]", "**.[oO][gG][gG]", "**.[oO][pP][uU][sS]", "**.[pP][nN][gG]", "**.[rR][tT][tT][tT][lL]", "**.[sS][mM][fF]", "**.[tT][fF][lL][iI][tT][eE]", "**.[wW][aA][vV]", "**.[wW][eE][bB][mM]", "**.[wW][eE][bB][pP]", "**.[wW][mM][aA]", "**.[wW][mM][vV]", "**.[xX][mM][fF]"]
  }
}

The documentation suggests we should see PAGE_ALIGNMENT_16K or PAGE_ALIGNMENT_4K here. But neither is present.

ohnorobo avatar Dec 16 '25 14:12 ohnorobo

More detail in the play store says:

Uncompressed native libraries are not zip aligned for 16 KB within your app. To resolve this, [fix your AGP configuration](https://developer.android.com/guide/practices/page-sizes#update-packaging).

This links to documentation saying

Update the packaging of your shared libraries
Upgrade to AGP version 8.5.1 or higher and use uncompressed shared libraries.

Currently our shared libraries are uncompressed. Image

Some are listed as 16KB, but none of them have the alignment warning shown in the docs here

We're no longer seeing the specific .so file warning we saw with a previous version.

ohnorobo avatar Dec 16 '25 14:12 ohnorobo

The documentation also mentions using AGP >= 8.5.1

We're currently using 8.7.3.

ohnorobo avatar Dec 16 '25 15:12 ohnorobo

I re-ren elf alignment on the final release build

./check_elf_alignment.sh Outline-Client.apk

Recursively analyzing Outline-Client.apk

NOTICE: Zip alignment check requires build-tools version 35.0.0-rc3 or higher.
  You can install the latest build-tools by running the below command
  and updating your $PATH:

    sdkmanager "build-tools;35.0.0-rc3"

=== ELF alignment ===
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/armeabi-v7a/libsentry.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/armeabi-v7a/libgojni.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/armeabi-v7a/libsentry-android.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/x86/libsentry.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/x86/libgojni.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/x86/libsentry-android.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/arm64-v8a/libsentry.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/arm64-v8a/libgojni.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/arm64-v8a/libsentry-android.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/x86_64/libsentry.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/x86_64/libgojni.so: \e[32mALIGNED\e[0m (2**14)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.UqFrDewBwC/lib/x86_64/libsentry-android.so: \e[32mALIGNED\e[0m (2**14)
\e[31mFound 2 unaligned libs (only arm64-v8a/x86_64 libs need to be aligned).\e[0m
=====================

So although they're mentioned as not needed, and don't show up as .so errors in the play store, maybe it's the libgojni.so libs

./check_elf_alignment.sh Outline-Client.apk | grep UNALIGNED
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.XLUOneB2M6/lib/armeabi-v7a/libgojni.so: \e[31mUNALIGNED\e[0m (2**12)
/var/folders/_s/1987wtss17b34gz5sv0f3mfm007mzb/T/Outline-Client_out_XXXXX.XLUOneB2M6/lib/x86/libgojni.so: \e[31mUNALIGNED\e[0m (2**12)

ohnorobo avatar Dec 16 '25 15:12 ohnorobo

I did at least figure out the bundletool issue

curl -L https://github.com/google/bundletool/releases/download/1.18.0/bundletool-all-1.18.0.jar --output bundletool.jar

upgrades to a newer bundletool

java -jar bundletool.jar dump config --bundle=client/platforms/android/app/build/outputs/bundle/release/app-release.aab
{
  "bundletool": {
    "version": "1.17.1"
  },
  "optimizations": {
    "splitsConfig": {
    },
    "uncompressNativeLibraries": {
      "enabled": true,
      "alignment": "PAGE_ALIGNMENT_16K"
    },
    "storeArchive": {
      "enabled": true
    }
  },
  "compression": {
    "uncompressedGlob": ["**.3[gG]2", "**.3[gG][pP]", "**.3[gG][pP][pP]", "**.3[gG][pP][pP]2", "**.[aA][aA][cC]", "**.[aA][mM][rR]", "**.[aA][wW][bB]", "**.[gG][iI][fF]", "**.[iI][mM][yY]", "**.[jJ][eE][tT]", "**.[jJ][pP][eE][gG]", "**.[jJ][pP][gG]", "**.[mM]4[aA]", "**.[mM]4[vV]", "**.[mM][iI][dD]", "**.[mM][iI][dD][iI]", "**.[mM][kK][vV]", "**.[mM][pP]2", "**.[mM][pP]3", "**.[mM][pP]4", "**.[mM][pP][eE][gG]", "**.[mM][pP][gG]", "**.[oO][gG][gG]", "**.[oO][pP][uU][sS]", "**.[pP][nN][gG]", "**.[rR][tT][tT][tT][lL]", "**.[sS][mM][fF]", "**.[tT][fF][lL][iI][tT][eE]", "**.[wW][aA][vV]", "**.[wW][eE][bB][mM]", "**.[wW][eE][bB][pP]", "**.[wW][mM][aA]", "**.[wW][mM][vV]", "**.[xX][mM][fF]"]
  }
}

Which has the missing alignment output. and says our .aab file is PAGE_ALIGNMENT_16K

ohnorobo avatar Dec 16 '25 18:12 ohnorobo

I was able to get a build that supports 16KB

It required adding a forced zip-align to the AAB

~/Library/Android/sdk/build-tools/36.0.0/zipalign -P 16 -f -v 4 client/platforms/android/app/build/outputs/bundle/release/app-release.aab client/platforms/android/app/build/outputs/bundle/release/app-release-zipaligned.aab

java -jar bundletool.jar build-apks         --bundle=client/platforms/android/app/build/outputs/bundle/release/app-release-zipaligned.aab --output=Outline.apks --mode=universal  --ks=keystore.p12        "--ks-pass=pass:$ANDROID_KEY_STORE_PASSWORD"      --ks-key-alias=privatekey  "--key-pass=pass:$ANDROID_KEY_STORE_PASSWORD"

I've updated that in the release instructions.

Here is the latest RC (490548) candidate in google play. Image

It's also possible to double-check the zip-alignment by running

~/Library/Android/sdk/build-tools/36.0.0/zipalign -c -v 4 Outline-Client.apk

on the RC

ohnorobo avatar Dec 17 '25 13:12 ohnorobo

Thanks for getting this done. This is fine for this release, but absolutely not what we should be doing. We shouldn't be messing with the AAB, that's the reason of our problems. Cordova and the Gradle project can generate the signed AAB in the proper format, perhaps it needs to be configured properly. We need a TODO to use what Android already gives us. Also migrate to App Bundles, which will make our lives easier.

fortuna avatar Dec 17 '25 19:12 fortuna

Alright, I'll leave this issue open for the future work then.

ohnorobo avatar Dec 18 '25 12:12 ohnorobo