This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: android-16kb-page-size-alignment-standard

Android 15 16KB Page Size ELF Native Library Memory Alignment Standard

Enforces strict 16KB (16384-byte) ELF segment memory boundary alignment across all compiled C/C++ native dependencies (.so) and packaging configurations. Prevents immediate runtime SIGSEGV aborts and dynamic linker rejection on Android 15 devices running 16KB page size kernels. Mandates modern NDK toolchains, explicit linker max-page-size flags, and 16KB-compatible zip alignment.

Prohibited Anti-Pattern: Shipping 4KB-aligned native libraries or legacy APK packaging causing linker crashes on 16KB Android 15 kernels

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Android 15 16KB Page Size ELF Native Library Memory Alignment Standard - Enforces strict 16KB (16384-byte) ELF segment memory boundary alignment across all compiled C/C++ native dependencies (.so) and packaging configurations. Prevents immediate runtime SIGSEGV aborts and dynamic linker rejection on Android 15 devices running 16KB page size kernels. Mandates modern NDK toolchains, explicit linker max-page-size flags, and 16KB-compatible zip alignment.
globs: **/build.gradle, **/build.gradle.kts, **/CMakeLists.txt, **/*.cmake, **/Android.mk, **/Application.mk
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/android-16kb-page-size-alignment-standard"
---

# Android 15 16KB Page Size ELF Native Library Memory Alignment Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Shipping 4KB-aligned native libraries or legacy APK packaging causing linker crashes on 16KB Android 15 kernels

## System Constraints
You are a Principal Mobile Systems Architect enforcing the Android 15 16KB Page Size Native Library Memory Alignment Standard. You must ensure that all native C/C++ code compiled via NDK, CMake, or ndk-build explicitly links with 16KB max-page-size ELF boundaries, uses NDK r27+ or explicit linker flags, and configures Android Gradle Plugin (AGP) packaging to prevent fatal dynamic linker crashes (dlopen failures) on 16KB-page mobile kernels.

## Strict Guidelines
- Engineers MUST ALWAYS enforce NDK r27 or newer, or explicitly inject `-Wl,-z,max-page-size=16384` into linker flags across all CMake, ndk-build, and C/C++ targets.
- Engineers MUST NOT rely on default NDK r26 or older linker configurations, which default to 4096-byte (4KB) ELF alignment and cause linker rejection on Android 15 16KB hardware.
- Build scripts MUST configure Gradle packaging to zip-align uncompressed native libraries to 16KB boundaries when using uncompressed dynamic linking.
- Prebuilt third-party `.so` binaries MUST be audited using `readelf -l <lib>.so | grep -A 1 LOAD` to verify that `Align` equals `0x4000` (16384) before ingestion.
- CI/CD pipelines MUST execute 16KB compliance checks using Android's SDK `alignment-checker` or `objdump`/`readelf` on all release APK and AAB artifacts.
- Engineers MUST NOT set `android:extractNativeLibs="false"` without verifying that Android Gradle Plugin (AGP 8.5.1+) and `zipalign -p 16384` are strictly applied.

## Bad vs Good Implementations
### CMake Native Library Linker Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Omits ELF maximum page size flags under older NDKs. This produces shared libraries with 4KB ELF segment alignment that fail to load with dynamic linker errors on Android 15 devices configured with 16KB kernels.
```cmake
# Non-compliant: Relies on legacy toolchain defaults (4KB page alignment)
cmake_minimum_required(VERSION 3.22.1)
project(native_engine CXX)

add_library(native_engine SHARED
    src/engine.cpp
    src/renderer.cpp
)

target_link_libraries(native_engine
    android
    log
)
```

#### Production Standard (Correct)
> **Standard**: Explicitly adds `-Wl,-z,max-page-size=16384` link option to the target. This guarantees that all `PT_LOAD` ELF segments are aligned to 16384-byte boundaries, fully satisfying Android 15 16KB kernel memory mapping requirements.
```cmake
# Compliant: Explicitly enforces 16KB ELF alignment for Android 15 compatibility
cmake_minimum_required(VERSION 3.22.1)
project(native_engine CXX)

add_library(native_engine SHARED
    src/engine.cpp
    src/renderer.cpp
)

# Enforce 16KB ELF segment alignment across both 64-bit and 32-bit architectures
target_link_options(native_engine PRIVATE
    "-Wl,-z,max-page-size=16384"
)

target_link_libraries(native_engine
    android
    log
)
```

### Android Gradle Plugin Module Configuration (build.gradle.kts)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: NDK r25 defaults to 4KB page size. Without modern NDK r27+ or linker flags passed through CMake arguments, compiled binaries crash on Android 15 16KB page devices.
```kotlin
// Non-compliant: Uses legacy NDK and lacks explicit 16KB page alignment linker options
android {
    compileSdk = 34
    ndkVersion = "25.2.9519653"

    defaultConfig {
        ndk {
            abiFilters += listOf("arm64-v8a", "x86_64")
        }
        externalNativeBuild {
            cmake {
                arguments += "-DANDROID_STL=c++_shared"
            }
        }
    }
}
```

#### Production Standard (Correct)
> **Standard**: Upgrades to NDK r27+, passes `-Wl,-z,max-page-size=16384` to ensure backward-compatible safety on CMake invocations, and configures clean packaging compatible with 16KB boundary alignment.
```kotlin
// Compliant: Uses NDK r27+ or passes explicit max-page-size linker arguments
android {
    compileSdk = 35
    // NDK r27+ sets 16KB page alignment by default
    ndkVersion = "27.0.12077973"

    defaultConfig {
        ndk {
            abiFilters += listOf("arm64-v8a", "x86_64")
        }
        externalNativeBuild {
            cmake {
                arguments += listOf(
                    "-DANDROID_STL=c++_shared",
                    "-DCMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=16384"
                )
            }
        }
    }

    packaging {
        jniLibs {
            useLegacyPackaging = false
        }
    }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Android 15 16KB Page Size ELF Native Library Memory Alignment Standard

Android 15 16KB Page Size ELF Native Library Memory Alignment Standard defines an industrial-grade behavioral standard for mobile engineering. Enforces strict 16KB (16384-byte) ELF segment memory boundary alignment across all compiled C/C++ native dependencies (.so) and packaging configurations. Prevents immediate runtime SIGSEGV aborts and dynamic linker rejection on Android 15 devices running 16KB page size kernels. Mandates modern NDK toolchains, explicit linker max-page-size flags, and 16KB-compatible zip alignment. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Shipping 4KB-aligned native libraries or legacy APK packaging causing linker crashes on 16KB Android 15 kernels Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftShipping 4KB-aligned native libraries or legacy APK packaging causing linker crashes on 16KB Android 15 kernelsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS enforce NDK r27 or newer, or explicitly inject `-Wl,-z,max-page-size=16384` into linker flags across all CMake, ndk-build, and C/C++ targets.

Engineers MUST ALWAYS enforce NDK r27 or newer, or explicitly inject `-Wl,-z,max-page-size=16384` into linker flags across all CMake, ndk-build, and C/C++ targets.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT rely on default NDK r26 or older linker configurations, which default to 4096-byte (4KB) ELF alignment and cause linker rejection on Android 15 16KB hardware.

Engineers MUST NOT rely on default NDK r26 or older linker configurations, which default to 4096-byte (4KB) ELF alignment and cause linker rejection on Android 15 16KB hardware.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Build scripts MUST configure Gradle packaging to zip-align uncompressed native libraries to 16KB boundaries when using uncompressed dynamic linking.

Build scripts MUST configure Gradle packaging to zip-align uncompressed native libraries to 16KB boundaries when using uncompressed dynamic linking.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Prebuilt third-party `.so` binaries MUST be audited using `readelf -l <lib>.so | grep -A 1 LOAD` to verify that `Align` equals `0x4000` (16384) before ingestion.

Prebuilt third-party `.so` binaries MUST be audited using `readelf -l <lib>.so | grep -A 1 LOAD` to verify that `Align` equals `0x4000` (16384) before ingestion.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

CI/CD pipelines MUST execute 16KB compliance checks using Android's SDK `alignment-checker` or `objdump`/`readelf` on all release APK and AAB artifacts.

CI/CD pipelines MUST execute 16KB compliance checks using Android's SDK `alignment-checker` or `objdump`/`readelf` on all release APK and AAB artifacts.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Engineers MUST NOT set `android

Engineers MUST NOT set `android:extractNativeLibs="false"` without verifying that Android Gradle Plugin (AGP 8.5.1+) and `zipalign -p 16384` are strictly applied.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Android 15 16KB Page Size ELF Native Library Memory Alignment Standard critical for AI coding assistants?

Enforces strict 16KB (16384-byte) ELF segment memory boundary alignment across all compiled C/C++ native dependencies (.so) and packaging configurations. Prevents immediate runtime SIGSEGV aborts and dynamic linker rejection on Android 15 devices running 16KB page size kernels. Mandates modern NDK toolchains, explicit linker max-page-size flags, and 16KB-compatible zip alignment. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Shipping 4KB-aligned native libraries or legacy APK packaging causing linker crashes on 16KB Android 15 kernels) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Android