I get this warning from the Android PlayStore:
Recompile your app with 16 KB native library alignment
Your app uses native libraries that are not aligned to support devices with 16 KB memory page sizes. These devices may not be able to install or start your app, or the app may start and then crash.
Is this something that SDL is OK with? Is it a simple compiler setting that needs changing? Or should we just ignore this warning?
You should definitely not ignore it, see Android Developers Blog: Prepare your apps for Google Play’s 16 KB page size compatibility requirement
SDL should be fine with it, how to fix it depends on build system you use, but basically you add -Wl,-z,max-page-size=16384
to your link flags, reference: Support 16 KB page sizes | Compatibility | Android Developers
I use Android Studio. Is there an easy setting for that?
How do you build your SDL?
I just downloaded all the SDL source code, and tweaked the example given by SDL. I followed all the instructions in the Lazy Foo tutorial.
Is example project android-project from SDL source? It uses ndk-build by default, just add APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true
line to your Application.mk
if you use ndk<=27. ndk>=28 will compile code with 16k pages support by default.
I think so, although it was several years ago I set things up so it may be an older version of that!
In my Application.mk I have:
APP_PLATFORM=android-19
and in my build.gradle I have:
minSdkVersion 23
don’t know if those ought to be the same, or if one over-rides the other. I try and keep it as low as possible for as many older devices to be compatible. So I guess I should add the:
APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true
I’ve just noticed this and am looking into it. There’re a few things to consider. For now, add this to your app’s build.gradle, put this inside defaultConfig
:
externalNativeBuild {
cmake {
path 'jni/CMakeLists.txt'arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
}
}
Do you prefer to compress your native libraries in your APK (so Android unpacks them), or pack them uncompressed? It seems that the system might automatically align when it unpacks from compressed. The disadvantage is app startup time, which is a fraction of a second from what I’ve seen.
I’m going to do some testing on an emulated 16 KB Page Size system image and report back.
1 Like
Just a quickie… yataro’s suggestion is better if you’re using Android Studio. The build.gradle addition I suggested is for people using CMake.
Testing my app on 16 KB Page Size emulator and it does indeed crash “Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR)”, which I assume (and hope) it’s due to not being 16 KB aligned.
My app’s native libs are compressed, so that’s not enough to avoid any issues due to apk native alignment.
Adding APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true
to Application.mk
was enough to get it working.
There’s mention of needing to add `LOCAL_LDFLAGS += “-Wl,-z,max-page-size=16384”, but I didn’t need to.
I’m targeting 34 with a min SDK of 21. I can’t seem to get my NDK higher than 27.0.12…, which is lower than the required 28, which would supposedly automatically set up 16 KB requirements.