androidandroid-ndk

How can I build and check NDK libraries for 16KB pages on Android from the command line?


I'm an partially sighted programmer who is far happier with a command line than an IDE, and finds IDE build systems very confusing. I'm successfully building shared libraries using the Android NDK from C and C++ code.

How do I make my shared libraries compatible with 16KB memory pages?


Solution

  • Context

    From November 1st 2025, new and updated Android apps must be compatible with 16KB memory pages, in addition to the classic 4KB memory pages, to be listed on Google Play. That requirement breaks down like this:

    Devices with 32-bit CPUs will only ever use 4KB pages, so 16KB compatibility is only relevant for 64-bit native code libraries. But 16KB compatibility is effectively compulsory for them.

    16KB-compatible libraries are automatically 4KB-compatible

    There's no need to produce two 64-bit versions. If you provide both 32-bit and 64-bit libraries, you only need to change the 64-bit ones.

    Source changes

    Usually, none. If your native code uses the system memory page size, either by hard-coding it or by using the PAGE_SIZE macro, you'll need to change that to use getpagesize() or sysconf(_SC_PAGESIZE). Then look for uses of mmap() and other calls that require page-aligned arguments, and change them.

    Linker option changes

    Add -Wl,-z,max-page-size=16384 to your linking command. If you use C++, you'll need to use the C++ run-time library from NDK27 or later. Earlier ones aren't 16KB-compatible.

    Checking your libraries

    With the NDK tools on your path, run:

    llvm-objdump -p /path/to/your/native/library.so | grep LOAD
    

    Alignment of 2**12 is 4KB-compatible and not 16KB-compatible.

    Alignment of 2**14 is 16KB-compatible, and also 4KB-compatible.