Skip to content

Android libraries are 4 KB aligned when the build hook gets an NDK older than r28 (Google Play 16 KB rule) #116

Open

Description

@freeKC

The Flutter tool hands the build hook the NDK of ANDROID_NDK_HOME before Gradle's ndkVersion. On GitHub's ubuntu-24.04 runners that is NDK r27d, whose linker aligns LOAD segments on 4 KB, so in our app the Rust library was the only 64 bit library of the APK below 16 KB, while Gradle built the rest with r28c. Google Play requires 16 KB alignment for the 64 bit libraries of apps targeting Android 15 or later, and from 1 February 2027 it will no longer accept updates that do not meet it (Support 16 KB page sizes). Adding -C link-arg=-Wl,-z,max-page-size=16384 to the Android targets in .cargo/config.toml fixed it whatever the NDK; fzyzcjy/flutter_rust_bridge#3426 proposes the same for its own Native Assets path. Would you take a pull request that passes this flag by default for the Android targets? It is harmless with r28 and later, which already align on 16 KB.

For reference, the flag as we pass it, on the three Android targets:

[target.aarch64-linux-android]
rustflags = ["-C", "link-arg=-Wl,-z,max-page-size=16384"]

[target.armv7-linux-androideabi]
rustflags = ["-C", "link-arg=-Wl,-z,max-page-size=16384"]

[target.x86_64-linux-android]
rustflags = ["-C", "link-arg=-Wl,-z,max-page-size=16384"]

LLD keeps the last max-page-size it is given, so the flag wins over the 4 KB default of an older NDK. With a linker wrapper that passes 4 KB first, as the r27 driver does, readelf -lW showed 0x4000 on every LOAD segment of the three targets with the flag, and 0x1000 without it.

Activity

  1. GregoryConrad commented on Oct 21, 2026

    @GregoryConrad
    Owner

    Hey, thanks for opening the issue. If this change doesn’t break pre-existing builds or older devices (doesn’t seem like it would?) then a PR would be welcome. For some reason I thought we already had support for that here from another issue that was opened previously, but clearly I’m remembering wrong if it’s still an issue.

  2. freeKC commented on Oct 22, 2026

    @freeKC
    Author

    Thanks for the quick answer. I opened #117: it passes the flag for the two 64 bit Android targets through a small wrapper around the NDK's clang, so the user's rustflags are left alone, and with NDK r28 the built library comes out byte for byte the same as today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions