Recent

Author Topic: Google Play Store requires 16KB native library alignment from Android 15  (Read 10116 times)

Manlio

  • Full Member
  • ***
  • Posts: 170
  • Pascal dev
On the Google Play Store dashboard I'm reading that starting with Android 15 it is recommended to "Recompile your app with 16 KB native library alignment". Failure to do that may cause apps to fail to load the library, or to just crash.

I started studying the matter but I didn't make much progress. Is there anyone who knows how to do that?

Thank you!!

manlio mazzon gmail

neuro

  • Jr. Member
  • **
  • Posts: 95
https://developer.android.com/guide/practices/page-sizes
Support 16 KB page sizes
16 KB Google Play compatibility requirement
Starting November 1st, 2025, all new apps and updates to existing apps submitted to Google Play and targeting Android 15+ devices must support 16 KB page sizes.
--------------------------
Android NDK r28 and higher
NDK version r28 and higher compile 16 KB-aligned by default.
--------------------------
Android NDK r27
To support compiling 16 KB-aligned shared libraries with Android NDK version r27 and higher, you need to update your ndk-build, build.gradle, build.gradle.kts, or linker flags as follows:
In your Application.mk:
APP_SUPPORT_FLEXIBLE_PAGE_SIZES := true
--------------------------
Android NDK r26 and lower
Update your Android.mk to enable 16 KB ELF alignment:
LOCAL_LDFLAGS += "-Wl,-z,max-page-size=16384"

nicelybrewed

  • New Member
  • *
  • Posts: 26
Has anyone tested this to get 16KB alignment in LAMW?
Lazarus v3.8, LAMW v0.8.6.4-blue, NDK v22b, Android 15, Windows 11 mainly but also use LAMW on Linux.

nobody.00

  • New Member
  • *
  • Posts: 25
LAMW Manager added support to 16kb on 64 bits build, directly of compiler
Now this LD_FLAGS required has been add to fpc-android.cfg
Get the new lamw_manager when this is required!
But still supports to NDK r22b, but I'm preparing enviroment to migrate to ndk r28 with Clang LLVM
« Last Edit: August 13, 2025, 10:10:18 pm by nobody.00 »

nicelybrewed

  • New Member
  • *
  • Posts: 26
Ah, cool, thanks!  :)
Lazarus v3.8, LAMW v0.8.6.4-blue, NDK v22b, Android 15, Windows 11 mainly but also use LAMW on Linux.

nobody.00

  • New Member
  • *
  • Posts: 25
To add support to 16 KB pages to ndk <= r22b add this ld flags in aarch64/android or x86_64/android:

-k-z common-page-size=16384
-k-z max-page-size=16384
« Last Edit: August 17, 2025, 04:35:10 pm by nobody.00 »

han

  • Full Member
  • ***
  • Posts: 137
I put the two lines in Lazarus at the project options and get this warning:

Warning: Only one source file supported, changing source file to compile from "common-page-size=16384" into "max-page-size=16384"
Warning: Only one source file supported, changing source file to compile from "max-page-size=16384" into "astap_command_line.lpr"

I'm using and FPCupdeLuxe cross compiler Linix to Android.  How to fix this?


PascalDragon

  • Hero Member
  • *****
  • Posts: 6398
  • Compiler Developer
I'm using and FPCupdeLuxe cross compiler Linix to Android.  How to fix this?

You need to quote the options correctly (not tested):

Code: [Select]
-k"-z common-page-size=16384" -k"-z max-page-size=16384"
or

Code: [Select]
-k"-z common-page-size=16384 -z max-page-size=16384"

han

  • Full Member
  • ***
  • Posts: 137
Thanks. Both options still give a warning. Now I understand they should be entered as:

-k-z
-kcommon-page-size=16384
-k-z
-kmax-page-size=16384

No warning and the file size increases. I still have to test it in Android

Quote
Each -k only forwards the immediate next token to the linker.

han

  • Full Member
  • ***
  • Posts: 137
The following project option

-k-z
-kcommon-page-size=16384
-k-z
-kmax-page-size=16384

 increase the file size but the 16kb warning does not go away.

I have try to compile with a fresh LAWM manager installer. I see in the fpc.cfg the following:

Quote
#IFDEF CPUAARCH64
-Xd
-XPaarch64-linux-android-
-FlC:\lamw_manager\LAMW\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\lib\aarch64-linux-android\30
-FLlibdl.so
-FDC:\lamw_manager\LAMW\sdk\ndk-bundle\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\bin
-FuC:\lamw_manager\LAMW\LAMW4Windows\fpc\$fpcversion\units\$fpctarget
-FuC:\lamw_manager\LAMW\LAMW4Windows\fpc\$fpcversion\units\$fpctarget\*
-FuC:\lamw_manager\LAMW\LAMW4Windows\fpc\$fpcversion\units\$fpctarget\rtl
-k-z common-page-size=16384
-k-z max-page-size=16384
#ENDIF

But unfortunately the 16kb warning does not go away. Also the resulting program is not functional. My tester uses Android studio.

My program is a command-line tool. There are even more problems :

FpCupdeluxe installation, Linux to Android cross compiling using fpc 3.2.2. creates a functional Android program. But only if interpreter is adapted as follows:

This is initially reported for the file:
file ./astap_cli
./astap_cli: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter libdl.so, BuildID[sha1]=fd5d50db766cf49c9b21ed8dcde3384c36f9ec40, stripped

For this I'm using patchelf as a fix:
patchelf --set-interpreter /system/bin/linker64 ./astap_cli

file ./astap_cli
./astap_cli: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, BuildID[sha1]=fd5d50db766cf49c9b21ed8dcde3384c36f9ec40, stripped

But cross compiling from Linux to Android using FPC 3.3.1 (installed by FPcupDeLuxe) then the Android command-line program doesn't work anymore.

So not much progress here. Does anybody have an hint how to solve the 16kb warning and above cross compiling problems?













« Last Edit: August 24, 2025, 09:53:41 pm by han »

abouchez

  • Full Member
  • ***
  • Posts: 137
    • Synopse
Re: Google Play Store requires 16KB native library alignment from Android 15
« Reply #10 on: August 25, 2025, 07:56:55 am »
Searching the FPC compiler sources, I found that the value seems hardcoded to 4KB:
Code: Pascal  [Select][+][-]
  1. procedure TLinkerAndroid.SetDefaultInfo;
  2. var
  3.   s: string;
  4. begin
  5.   with Info do
  6.    begin
  7.      { Specify correct max-page-size and common-page-size to prevent big gaps between sections in resulting executable }
  8.      s:='ld -z max-page-size=0x1000 -z common-page-size=0x1000 -z noexecstack -z now -z relro --build-id $OPT -L. -T $RES -o $EXE';
  9.  

My guess is that the supplied command line option is not enough to fix this.


DonAlfredo

  • Hero Member
  • *****
  • Posts: 1877
Re: Google Play Store requires 16KB native library alignment from Android 15
« Reply #12 on: August 25, 2025, 11:23:12 am »
I a fix is found, I will happily implement the fix into fpcupdeluxe.

han

  • Full Member
  • ***
  • Posts: 137
Re: Google Play Store requires 16KB native library alignment from Android 15
« Reply #13 on: August 25, 2025, 03:38:30 pm »
Thanks for looking into the FPC code.

Today I tried the project options
Code: Pascal  [Select][+][-]
  1. -k-z
  2. -kcommon-page-size=16384
  3. -k-z
  4. -kmax-page-size=16384

again and did in Linux the test with "readelf -l executable" as mentioned in the article. I did the test on a Linux X86_64 and Android aarch64 executable. The align value changes from $1000 to $4000!. See screenshots. Why there is still a 16kb warning, I can think only of the following explanations:

1) The Android test fails to test the 16kb alignment properly
2) My tester did something wrong (I have no Android setup here to test it, but I will try to set it up myself)

Note also that when the target is Android aarch64, the compiler produces a DYN (share object file) which I still do not understand. A few years ago the compiler was producing an executable if I remember correctly.

Files where compiled with a setup created by FpCupDeLuxe in Linux.

nobody.00

  • New Member
  • *
  • Posts: 25
Re: Google Play Store requires 16KB native library alignment from Android 15
« Reply #14 on: August 26, 2025, 05:16:19 pm »
The following project option

-k-z
-kcommon-page-size=16384
-k-z
-kmax-page-size=16384

 increase the file size but the 16kb warning does not go away.

I have try to compile with a fresh LAWM manager installer. I see in the fpc.cfg the following:

Quote
#IFDEF CPUAARCH64
-Xd
-XPaarch64-linux-android-
-FlC:\lamw_manager\LAMW\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\lib\aarch64-linux-android\30
-FLlibdl.so
-FDC:\lamw_manager\LAMW\sdk\ndk-bundle\toolchains\aarch64-linux-android-4.9\prebuilt\windows-x86_64\bin
-FuC:\lamw_manager\LAMW\LAMW4Windows\fpc\$fpcversion\units\$fpctarget
-FuC:\lamw_manager\LAMW\LAMW4Windows\fpc\$fpcversion\units\$fpctarget\*
-FuC:\lamw_manager\LAMW\LAMW4Windows\fpc\$fpcversion\units\$fpctarget\rtl
-k-z common-page-size=16384
-k-z max-page-size=16384
#ENDIF

But unfortunately the 16kb warning does not go away. Also the resulting program is not functional. My tester uses Android studio.

My program is a command-line tool. There are even more problems :

FpCupdeluxe installation, Linux to Android cross compiling using fpc 3.2.2. creates a functional Android program. But only if interpreter is adapted as follows:

This is initially reported for the file:
file ./astap_cli
./astap_cli: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter libdl.so, BuildID[sha1]=fd5d50db766cf49c9b21ed8dcde3384c36f9ec40, stripped

For this I'm using patchelf as a fix:
patchelf --set-interpreter /system/bin/linker64 ./astap_cli

file ./astap_cli
./astap_cli: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, BuildID[sha1]=fd5d50db766cf49c9b21ed8dcde3384c36f9ec40, stripped

But cross compiling from Linux to Android using FPC 3.3.1 (installed by FPcupDeLuxe) then the Android command-line program doesn't work anymore.

So not much progress here. Does anybody have an hint how to solve the 16kb warning and above cross compiling problems?

I need  more information about your project ? Do you use lazarus create by LAMW Manager ?

Try run same test with your library
My test on linux using lamw_manager :

« Last Edit: August 26, 2025, 05:24:03 pm by nobody.00 »

 

TinyPortal © 2005-2018