Skip to content

fix(android): align native libs to 16 KB pages#30

Merged
TaprootFreak merged 1 commit into
developfrom
fix/16kb-page-alignment
Jun 9, 2026
Merged

fix(android): align native libs to 16 KB pages#30
TaprootFreak merged 1 commit into
developfrom
fix/16kb-page-alignment

Conversation

@TaprootFreak

Copy link
Copy Markdown

Problem

Google Play flags the RealUnit wallet bundle: its native code is only 4 KB page aligned, so it cannot run on Android 15+ devices that use 16 KB memory pages. The offending library is libgojni.so (the gomobile-built Go binding shipped in android/libs/api.aar) — its arm64-v8a PT_LOAD segments had p_align = 0x1000 (4 KB). Every other native lib in the app (libflutter, libapp, libsqlite3mc, tensorflowlite, …) is already ≥ 16 KB; libgojni.so was the only 4 KB outlier.

Fix

Pass -extldflags=-Wl,-z,max-page-size=16384 to gomobile bind in run_build_tool_android.sh. The flag reaches the NDK linker (lld) and forces 16 KB ELF page alignment. NDK r27 does not default to 16 KB, so the explicit flag is required.

android/libs/api.aar regenerated with the flag.

Verification

  • jni/arm64-v8a/libgojni.so PT_LOAD p_align: 0x10000x4000 (16 KB)
  • PR gate green locally: go vet, go test -race (api + u2fhid), dart format --set-exit-if-changed, flutter analyze, flutter test (11 passed)

Test plan

  • CI green
  • After merge + tag: bump the bitbox_flutter ref in the RealUnit app, rebuild the AAB, and confirm lib/arm64-v8a/libgojni.so reports 16 KB alignment in the final bundle

Pass -extldflags=-Wl,-z,max-page-size=16384 to gomobile bind so the
emitted .so libraries use 16 KB ELF page alignment. Android 15 devices
can run with 16 KB memory pages and Google Play rejects bundles whose
native code is only 4 KB aligned. The prebuilt arm64-v8a libgojni.so in
android/libs/api.aar was 4 KB aligned (p_align 0x1000) and is now 0x4000.

Regenerated android/libs/api.aar via run_build_tool_android.sh.
@TaprootFreak TaprootFreak marked this pull request as ready for review June 9, 2026 17:44
@TaprootFreak TaprootFreak merged commit a0de0f8 into develop Jun 9, 2026
3 checks passed
TaprootFreak added a commit to RealUnitCH/app that referenced this pull request Jun 9, 2026
)

## Why

Google Play flags the app bundle: its native code is not 16 KB page
aligned, so it cannot run on Android 15+ devices that use 16 KB memory
pages. The only offending library was `libgojni.so` (the gomobile-built
Go binding shipped by `bitbox_flutter`) — its arm64-v8a `PT_LOAD`
segments were `p_align = 0x1000` (4 KB). Every other native lib in the
bundle (libflutter, libapp, libsqlite3mc, libtensorflowlite_jni, …) is
already ≥ 16 KB.

## What

Bump `bitbox_flutter` `v0.0.8 → v0.0.9`. v0.0.9 rebuilds the gomobile
binding with `-extldflags=-Wl,-z,max-page-size=16384`, producing 16
KB-aligned `.so` libraries. See DFXswiss/bitbox_flutter#30.

`pubspec.lock` updated to the v0.0.9 commit (`6172a2e`); no other lock
entries change.

## Verification

- `bitbox_flutter` v0.0.9 `jni/arm64-v8a/libgojni.so` + `x86_64`:
`p_align` `0x1000` → **`0x4000`** (16 KB)
- API-safe bump: javap public signatures (146 lines) and exported
dynamic symbols (284) are **byte-identical** between v0.0.8 and v0.0.9 —
only ELF alignment changed, so no source-level impact
- `bitbox_flutter` PR gate green (go vet/test, dart format, analyze,
flutter test)

## Test plan

- [ ] App CI green (Analyze & Test, Visual Regression, Coverage Floor
Gate)
- [ ] Release build: confirm `lib/arm64-v8a/libgojni.so` reports 16 KB
alignment in the final AAB and the Play Console warning clears
TaprootFreak added a commit that referenced this pull request Jun 9, 2026
Brings in #30's 16 KB page-alignment fix. The api.aar conflict is resolved by
rebuilding the gomobile binding with BOTH the 16 KB alignment flag
(-extldflags=-Wl,-z,max-page-size=16384, from the merged build script) AND the
new DeviceStatus export, so the merged artefact keeps Android 15+ support and
exposes the device status. libgojni.so PT_LOAD p_align verified at 0x4000.
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.

1 participant