react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Need support for 16KB page size on Android

Open bc-lee opened this issue 1 year ago • 35 comments

Description

Android 15 offers an option for OEMs to use a 16KB page size for better performance [1]. This change is significant, as all shared objects (.so files in APKs) must be recompiled with the new page size. According to the Android team [2][3], 16KB page size compatibility will be required for app uploads to the Play Store next year (2025).

It seems that React-Native is not compatible with the 16KB page size. If I try to run a React-Native project on an emulator with a 16KB page size, I get the following error in the logcat:

Library 'libreact_render_componentregistry.so' is not PAGE(16384)-aligned - will not be able to open it directly from apk.

I checked all shared objects in the APK using my script check_elf_page_size.py and found that all shared objects use a 4KB page size.

$ check_elf_page_size.py android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/*.so
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libc++_shared.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libexpo-modules-core.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libfabricjni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libfbjni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libfolly_runtime.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libgifimage.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libglog.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libhermes.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libhermes_executor.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libhermesinstancejni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libimagepipeline.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libjscinstance.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libjsi.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libjsijniprofiler.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libjsinspector.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libmapbufferjni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libnative-filters.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libnative-imagetranscoder.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_codegen_rncore.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_cxxreactpackage.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_debug.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_devsupportjni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_featureflags.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_featureflagsjni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_nativemodule_core.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_newarchdefaults.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_render_componentregistry.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_render_core.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_render_debug.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_render_element.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_render_graphics.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_render_imagemanager.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_render_mapbuffer.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreact_utils.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreactnativeblob.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreactnativejni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreactperfloggerjni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libreanimated.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/librninstance.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/librnscreens.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/librrc_image.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/librrc_legacyviewmanagerinterop.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/librrc_view.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libruntimeexecutor.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libstatic-webp.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libturbomodulejsijni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libuimanagerjni.so: 4096
Page Size of android/app/build/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libyoga.so: 4096

(Of course, one can manually check the page size of each shared object using the readelf -Wl command.)

I think React-Native should support the 16KB page size for the future.

[1] https://developer.android.com/guide/practices/page-sizes [2] https://android-developers.googleblog.com/2024/05/the-second-beta-of-android-15.html [3] https://issuetracker.google.com/issues/346830813#comment3

Steps to reproduce

  1. Create a new Android emulator with a 16KB page size using the "Google APIs Experimental 16k Page Size Intel x86_64 Atom System Image" (see [1] for more details).
  2. Create a new React-Native project using npx react-native init.
  3. Build and run the project on the emulator using npx expo run:android.

React Native Version

0.74.2

Affected Platforms

Runtime - Android

Output of npx react-native info

$ npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 14.5
  CPU: (10) arm64 Apple M1 Max
  Memory: 101.97 MB / 32.00 GB
  Shell:
    version: 5.2.26
    path: /opt/homebrew/bin/bash
Binaries:
  Node:
    version: 18.20.2
    path: ~/.nvm/versions/node/v18.20.2/bin/node
  Yarn:
    version: 1.22.22
    path: ~/.nvm/versions/node/v18.20.2/bin/yarn
  npm:
    version: 10.7.0
    path: ~/.nvm/versions/node/v18.20.2/bin/npm
  Watchman:
    version: 2024.06.10.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/redacted/.rvm/gems/ruby-3.1.4/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: EAP AI-241.17890.1.2412.11972402 AI-241.17890.1.2412.11972402
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 3.1.4
    path: /Users/redacted/.rvm/rubies/ruby-3.1.4/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.74.2
    wanted: 0.74.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

Library 'libreact_render_componentregistry.so' is not PAGE(16384)-aligned - will not be able to open it directly from apk.

Reproducer

npx create-expo-app@latest

Screenshots and Videos

Screenshot 2024-06-19 at 09 29 03

bc-lee avatar Jun 19 '24 00:06 bc-lee

:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

github-actions[bot] avatar Jun 19 '24 00:06 github-actions[bot]

I think React-Native should support the 16KB page size for the future.

Agree. We haven't planned support for 16K page size in the near future as we're focused on rolling out the New Architecture.

To unblock yourself you can however:

  1. Turn on build from source https://reactnative.dev/contributing/how-to-build-from-source
  2. Bump the NDK to 27
  3. Use the -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON parameter as suggested in the guide (you'll have to patch.package also node_modules/react-native/ReactAndroid/build.gradle.kts to pass that config there as well).

cortinico avatar Jun 19 '24 16:06 cortinico

I created the following repo where I use RN 0.74.3. (Repo)

  1. Bumbed NDK to 27.0.11718014
  2. Patched node_modules/react-native/ReactAndroid/build.gradle.ks
  3. Created an Emulator supporting a 16KB page size
  4. Build and launch from Android Studio Canary2024.1.2 Canary 5 as suggested here https://developer.android.com/guide/practices/page-sizes#16kb-emulator

As a result, I got the following exception after the app launched:

2024-07-14 15:42:38.414  3431-3431  libc                    com.elf16check                       
 A  Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7299c27d4cc0 in tid 3431 (com.elf16check), pid 3431 (com.elf16check)

2024-07-14 15:42:40.597  3502-3502  DEBUG                   crash_dump64                         
A  Cmdline: com.elf16check

2024-07-14 15:42:40.598  3502-3502  DEBUG                   crash_dump64                        
 A  pid: 3431, tid: 3431, name: com.elf16check  >>> com.elf16check <<<

Pulimet avatar Jul 14 '24 12:07 Pulimet

@bc-lee @Pulimet Have you tried adding the broadcast receiver capability which was mandatory after Android SDK 34 upgrade? https://stackoverflow.com/questions/78765352/updated-compilesdkversion-to-34-in-react-native-project-but-unable-to-connect-t Before adding this, I was facing same crash for react-native app.

jakhil232 avatar Jul 22 '24 06:07 jakhil232

I created the following repo where I use RN 0.74.3. (Repo)

  1. Bumbed NDK to 27.0.11718014
  2. Patched node_modules/react-native/ReactAndroid/build.gradle.ks
  3. Created an Emulator supporting a 16KB page size
  4. Build and launch from Android Studio Canary2024.1.2 Canary 5 as suggested here https://developer.android.com/guide/practices/page-sizes#16kb-emulator

As a result, I got the following exception after the app launched:

2024-07-14 15:42:38.414  3431-3431  libc                    com.elf16check                       
 A  Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7299c27d4cc0 in tid 3431 (com.elf16check), pid 3431 (com.elf16check)

2024-07-14 15:42:40.597  3502-3502  DEBUG                   crash_dump64                         
A  Cmdline: com.elf16check

2024-07-14 15:42:40.598  3502-3502  DEBUG                   crash_dump64                        
 A  pid: 3431, tid: 3431, name: com.elf16check  >>> com.elf16check <<<

Same issue for me as well, tried all the solutions given for 16kb page size support - https://developer.android.com/guide/practices/page-sizes#groovy_1

My version compatibility table for react native app -

Module Name Version Recommended Tested On
React Native -- 0.72.3
Android Studio Koala 2024.1.2 | Canary 5 Koala 2024.1.1
Android Gradle Plugin >= 8.3.0 8.5.1
Gradle > 8.2 8.7
Build Tools Version 35.0 35.0
Compile SDK 35.0 35.0
Target SDK 35.0 35.0
CMake 3.22.1 3.22.1
Kotlin 1.9.22 1.6.0 (Issue on 1.9.22)

After trying all the possible solutions, the app was successfully built & installed on the emulator. But the app couldn't launch as there was a repetitive crash occurring.

Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x708d31bd64 in tid 22188

Was anyone able to install react native app successfully on 16kb page size devices?

jakhil232 avatar Jul 22 '24 08:07 jakhil232

@cortinico could you help in this after developers above tried proposed solution ? it will be more appreciated .

MahmoudMabrok avatar Jul 28 '24 07:07 MahmoudMabrok

I created the following repo where I use RN 0.74.3. (Repo)

  1. Bumbed NDK to 27.0.11718014
  2. Patched node_modules/react-native/ReactAndroid/build.gradle.ks
  3. Created an Emulator supporting a 16KB page size
  4. Build and launch from Android Studio Canary2024.1.2 Canary 5 as suggested here https://developer.android.com/guide/practices/page-sizes#16kb-emulator

As a result, I got the following exception after the app launched:

2024-07-14 15:42:38.414  3431-3431  libc                    com.elf16check                       
 A  Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7299c27d4cc0 in tid 3431 (com.elf16check), pid 3431 (com.elf16check)

2024-07-14 15:42:40.597  3502-3502  DEBUG                   crash_dump64                         
A  Cmdline: com.elf16check

2024-07-14 15:42:40.598  3502-3502  DEBUG                   crash_dump64                        
 A  pid: 3431, tid: 3431, name: com.elf16check  >>> com.elf16check <<<

did you check if libs aligned or not ? @Pulimet

MahmoudMabrok avatar Jul 28 '24 07:07 MahmoudMabrok

@MahmoudMabrok

./alignment.sh apk | grep "arm64-v8a"

Results

apk/lib/arm64-v8a/libreact_newarchdefaults.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreactperfloggerjni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libjsi.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_render_mapbuffer.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_featureflagsjni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libnative-filters.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_codegen_rncore.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libfbjni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libjscinstance.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/librninstance.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libuimanagerjni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libfabricjni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_utils.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreactnativeblob.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libnative-imagetranscoder.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libmapbufferjni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libjsijniprofiler.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libjsinspector.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_render_element.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libglog.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libhermes_executor.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libimagepipeline.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_debug.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_cxxreactpackage.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libturbomodulejsijni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_devsupportjni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/librrc_view.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libruntimeexecutor.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libfolly_runtime.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_featureflags.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libhermes.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libc++_shared.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_render_debug.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libhermesinstancejni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_render_graphics.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_render_imagemanager.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_render_componentregistry.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_nativemodule_core.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/librrc_legacyviewmanagerinterop.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreact_render_core.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libreactnativejni.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/librrc_image.so: \e[31mUNALIGNED\e[0m (212) apk/lib/arm64-v8a/libyoga.so: \e[31mUNALIGNED\e[0m (2**12)`

Pulimet avatar Jul 28 '24 09:07 Pulimet

Seems alignment not done properly. @Pulimet I cloned your repo and I am going to add some updates, hope it make lib aligned. pray for me.

MahmoudMabrok avatar Jul 28 '24 11:07 MahmoudMabrok

same results, all are unAligned.

I found two ndk version in your sample repo @Pulimet one is 27 and other 26 inside rn itself it is 26.

I added steps for 26 version but I got same issue.

is RN use preBuilt .so library ? @cortinico

MahmoudMabrok avatar Jul 28 '24 11:07 MahmoudMabrok

Yes we do ship prebuilts for all the .so inside React Native.

cortinico avatar Jul 28 '24 19:07 cortinico

@jakhil232 could you please check alignment of .so and share with us results ?

MahmoudMabrok avatar Jul 29 '24 09:07 MahmoudMabrok

@jakhil232 could you please check alignment of .so and share with us results ?

Same case for me as @Pulimet, mine libraries are unaligned as well. I think the alignment should come from React Native side, as they are shipping it. Also tried all the methods, given in the dock. @cortinico any timeline? as to when React Native will start shipping these changes?

jakhil232 avatar Jul 29 '24 09:07 jakhil232

Certainly, pinging React Native devs won't help, as they understand this issue and @cortinico has already commented like this: https://github.com/facebook/react-native/issues/45054#issuecomment-2179095866

We haven't planned support for 16K page size in the near future as we're focused on rolling out the New Architecture.

Folks, unless you want to build React Native from source, you will have to wait for these changes to be made.

bc-lee avatar Jul 29 '24 11:07 bc-lee

does solution building from source worked with you @bc-lee ? I used repo from @Pulimet and changed a lot of flags inside react native module inside node-modules but seems not reflected.

I wil search more and update you.

MahmoudMabrok avatar Jul 29 '24 15:07 MahmoudMabrok

Just a small update: I'm discussing with @Kudo (Expo) and folks at Google to understand the impact/urgency of this.

This change will require NDK 27 which got released several weeks ago and definitely won't land in React Native 0.75. Future versions (0.76 or 0.77) are up for debate.

The crucial bit for us to understand is wether devices on Android 15 will have the 16K support enabled by default or not, but it doesn't seems to be the case.

I'll update here as we know more.

cortinico avatar Aug 02 '24 10:08 cortinico

Just found this thread. 16KB support is planned for later this year as we are waiting for more details from Google and it is not a requirement for Android 15. I'll post an update as we get more clarity on what we need to do. (cc @cortinico )

alanleedev avatar Aug 06 '24 16:08 alanleedev

It's important SDKs like React are available before developers start trying this out. They are depending on SDKs such as this.

I want to mention, NDK r27 is not strictly necessary for this. You can use earlier NDKs. What NDK r27 offers is two things: libc++_shared.so prebuilt is aligned, and it has an option to undefine PAGE_SIZE for you. If you are using earlier versions of NDKs, you can still grep for PAGE_SIZE or delete it from the NDK headers as a local test, and that should get you past most if any page size assumptions the code has.

For older versions of the NDK, you can also get updated libc++_shared.so from our CI (or use a static libc++): https://developer.android.com/guide/practices/page-sizes#compile-r26-lower

If you can get it working on 16 KB and prove there are no other major runtime issues, I think that would be perfect to inform work estimates. I'm not too familiar with the React Native architecture, but Hermes is probably the biggest risk, since VMs may make page size assumptions. So, getting to the point that you can run that on a 16 KB device is probably the most important step to understanding if there is more work here beyond a recompile.

Android 15 will have the 16K support enabled by default or not, but it doesn't seems to be the case.

Confirming, it won't be by default.

smore-lore avatar Aug 06 '24 18:08 smore-lore

Hello, my app compile and run well on pixel8 android 15 qpr1 pagesize 16kb. But, when i build aab and upload to google play. I cannot download the app from google play, error lib not aligned on apk, stuck at 100%

hooliapps avatar Aug 25 '24 10:08 hooliapps

Google published a few more details in a blog post if that can help: https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html

fabiendem avatar Aug 28 '24 11:08 fabiendem

I'm recompiling a native .so library for my own Android app.

I recompiled the library by adding: LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384" in Android.mk APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true in Application.mk Then "make init" and "make" and now my App is working with Android 15 and Page size 15kb mode activated, with Android Studio Koala.

But, when launching Build AAB (signed) from Android Studio Koala, uploading the app to Google Play then downloading the app, i get the following errors: 09-03 22:26:02.654 1336 1697 E NativeLibraryHelper: Library 'libsqlc-native-driver.so' is not PAGE(16384)-aligned - will not be able to open it directly from apk. 09-03 22:26:02.654 1336 1697 W NativeHelper: Failure copying native libraries [errorCode=-2] 09-03 22:26:02.654 1336 1697 D PackageInstallerSession: Marking session 1857550392 as failed: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2

Do you know please how I can solve this issue ?

The .so lib seems correctly aligned (at least before build): ./libsqlc-native-driver.so: ALIGNED (2**14)

hooliapps avatar Sep 03 '24 20:09 hooliapps

@hooliapps I don't this may the right place to ask generic 16KB page size support issues. Anyway React Native does use native libraries and they do not yet support 16KB page size so you may still run into issues if you are using React Native.

alanleedev avatar Sep 04 '24 00:09 alanleedev

This specific issue is due to zip alignment. As of today, please follow these instructions: https://developer.android.com/guide/practices/page-sizes#update-packaging

smore-lore avatar Sep 04 '24 00:09 smore-lore

You may need to validate the alignment of the APK file.

For more information, see See https://developer.android.com/tools/zipalign

To confirm the alignment of existing.apk, use the following command. zipalign -c -P 16 -v 4 existing.apk

bc-lee avatar Sep 04 '24 02:09 bc-lee

Hello

Thanks for your response.

But i still have questions about zipalign:

  1. Can we use Android Jellyfish ? Or at least Koala is needed ?

  2. Can we build for SDK 34 (compile sdk) ? Or build tools 35 is needed ?

  3. Same question about target sdk

  4. How to use zipalign ? The provided example is for one APK. But Android Studio automatically generate the AAB Bundle (mandatory for Google Play), so i dont know if we need to edit a gradle or manifest file ? Or we need to build APK, zipalign then manually build a signed AAB ?

Best regards

hooliapps avatar Sep 04 '24 08:09 hooliapps

You need to upgrade to AGP >= 8.5.1. Please see instructions here: https://developer.android.com/build/agp-upgrade-assistant#run-upgrade-assistant

It will tell you exactly what is needed!

smore-lore avatar Sep 04 '24 20:09 smore-lore

Hello

Finally, i resolved the problem by adding this in /app/build.gradle, under android { block: packagingOptions { jniLibs { useLegacyPackaging = true } }

I didnt changed anything else, sdk 34. I have gradle version 8.4

hooliapps avatar Sep 04 '24 20:09 hooliapps

Yes, useLegacyPackaging also resolves the bundle alignment issue at the cost of slightly increased disk space usage since both the compressed and the uncompressed copies of .so files in your APK will be stored on an Android device when your application is installed. If this option is not specified and you use AGP 8.5.1+ instead, then disk space will only be used for the uncompressed copy, and there will be no compressed copy. Thank you!

smore-lore avatar Sep 04 '24 20:09 smore-lore

I have question about alignement. I recompiled all libs to 16, the libs who was in 4kb, but also the lib who was in 64kb.

It's ok ?

hooliapps avatar Sep 04 '24 23:09 hooliapps

Yes, 4->16 and 64->16 are both okay. It will be many years, if ever, before aligning to the 64k size is feasible in the Android ecosystem. I would not worry about it.

smore-lore avatar Sep 04 '24 23:09 smore-lore