Skip to content

fix: add 16KB page alignment support for Android#182

Open
Obehi234 wants to merge 1 commit intoLtbLightning:mainfrom
zamryeng:fix/16kb-page-alignment-upstream
Open

fix: add 16KB page alignment support for Android#182
Obehi234 wants to merge 1 commit intoLtbLightning:mainfrom
zamryeng:fix/16kb-page-alignment-upstream

Conversation

@Obehi234
Copy link

@Obehi234 Obehi234 commented Mar 4, 2026

Summary

Google Play now requires 16KB page alignment (0x4000) for native libraries targeting Android 15+ (API 35+). The current precompiled binaries shipped via Cargokit are built with 4KB alignment (0x1000), causing Play Store rejection.

This PR disables precompiled binary downloads to force source builds, which produce correct 16KB alignment when using NDK r28+.

Closes #181


Investigation & Root Cause

How Cargokit Resolves Binaries

Cargokit computes a SHA-256 hash of the Rust source files (src/*.rs, Cargo.toml, Cargo.lock, cargokit.yaml) and uses it to look up precompiled binaries from the url_prefix in cargokit.yaml. If a matching binary is found, it's downloaded and used directly. Source compilation only happens as a fallback.

The Problem

The precompiled binaries hosted at https://github.com/LtbLightning/bdk-flutter/releases/download/precompiled_ were built with an older NDK that defaults to 4KB page alignment. We verified this by downloading the aarch64-linux-android release artifact and inspecting it:

$ llvm-readelf -l libbdk_flutter.so

Program Headers:
  Type   Offset   VirtAddr   PhysAddr   FileSiz  MemSiz   Flg  Align
  LOAD   0x000000 0x00000000 0x00000000 0x...    0x...    R    0x1000  ← 4KB
  LOAD   ...                                              R E  0x1000  ← 4KB

Why .cargo/config.toml Alone Doesn't Fix It

During Flutter builds, Cargokit sets CARGO_ENCODED_RUSTFLAGS in android_environment.dart. This environment variable overrides all other rustflags sources, including .cargo/config.toml. So adding linker flags there only helps standalone cargo build invocations, not Flutter builds through Cargokit.

The actual 16KB alignment in Flutter builds comes from NDK r28+ defaulting to it in its linker.


Changes

File Change
rust/cargokit.yaml Commented out precompiled_binaries to force source builds
rust/.cargo/config.toml Added explicit 16KB linker flags for all Android targets (safety net for standalone cargo builds)

Verification

Build Method LOAD Alignment Play Store
Precompiled binary (current) 0x1000 (4KB) Rejected
Source build, NDK r28+ 0x4000 (16KB) Accepted

Tested end-to-end: built a Flutter app depending on bdk-flutter with this change, extracted libbdk_flutter.so from the APK, and confirmed 0x4000 alignment via llvm-readelf -l.

Tradeoffs

  • Build time increases — source compilation instead of downloading precompiled binaries
  • Recommended permanent fix — rebuild and republish precompiled binaries using NDK r28+, then re-enable the precompiled_binaries section. The config is commented out (not removed) to make this easy.

Disable precompiled binaries which are built with 4KB page alignment.
Google Play requires 16KB alignment for Android 15+ (API 35+).
Building from source with NDK r28+ produces correct alignment.

Also adds explicit linker flags in .cargo/config.toml as a safety net
for builds outside of Cargokit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

16KB alignment issue on google play

1 participant