Skip to content

Native lib libscout_crash_handler.so is 4KB-aligned — breaks Android 16 KB page-size compatibility #2

Description

@ankitranjandev

Summary

libscout_crash_handler.so ships with 4 KB ELF segment alignment (0x1000), so it
fails to load on Android devices using a 16 KB memory page size. This makes any app
that depends on scout_flutter non-compliant with Google Play's 16 KB page-size
requirement (mandatory for apps targeting Android 15+).

Every other native library in our app (Flutter engine, onnxruntime, pdfium, c++_shared,
etc.) is already ≥ 16 KB aligned — scout_flutter is the only one that isn't.

Version

  • scout_flutter: 0.1.21 (also confirmed unchanged in 0.1.22 — no alignment-related
    entry in the changelog)

Evidence

Running llvm-readelf -l on the arm64-v8a libs bundled in the built APK:

libflutter.so 0x10000 (64 KB) ✅
libc++_shared.so 0x4000 (16 KB) ✅
libonnxruntime.so 0x4000 (16 KB) ✅
libmodpdfium.so 0x4000 (16 KB) ✅
...
libscout_crash_handler.so 0x1000 (4 KB) ❌

The LOAD segment alignment must be a multiple of 16384 (0x4000) for 16 KB-page devices.

Root cause

android/src/main/jni/CMakeLists.txt sets no page-size linker flags, and
android/build.gradle pins no ndkVersion. As a result the module resolves to
NDK r27, whose default ELF max-page-size is 4 KB. (NDK r28+ defaults to 16 KB,
which is why consumers on newer NDKs see every other lib aligned correctly, but this
plugin still compiles against the older resolved toolchain.)

Suggested fix

Either bump the plugin's ndkVersion to r28+ (16 KB by default), or opt in explicitly
so it works regardless of the resolved NDK. In android/src/main/jni/CMakeLists.txt:

target_link_options(scout_crash_handler PRIVATE
    "-Wl,-z,max-page-size=16384,-z,common-page-size=16384")

(or add arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON" to the plugin's
externalNativeBuild { cmake { ... } }.)

Workaround (for other consumers)

We patched it downstream by scoping an override onto the scout_flutter subproject in
our app's root android/build.gradle, which produces a correctly aligned 0x4000 lib:

subprojects {
    plugins.withId('com.android.library') {
        if (project.name == 'scout_flutter') {
            android {
                ndkVersion = "28.2.13676358"
                defaultConfig {
                    externalNativeBuild {
                        cmake { arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON" }
                    }
                }
            }
        }
    }
}

References

- https://developer.android.com/guide/practices/page-sizes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions