Skip to content

ANDROID_NDK_HOME silently overrides the Android Gradle plugin's NDK #19

Closed

Description

@lemcoder

What happened

MikroSoundFont's published 0.4.0 and 0.4.1 AARs shipped 4 KB aligned Android libraries although the project (and its publish workflow) used NDK 28, which aligns to 16 KB pages by default. Local builds were correct; only CI builds were wrong.

The publish log shows every Android library built with /Users/runner/Library/Android/sdk/ndk/27.3.13750724. GitHub's macOS and Ubuntu runner images preset ANDROID_NDK_HOME to that NDK, and KonanConfig.resolve ranks the sources for androidNdk as:

  1. konan { config { androidNdk } }
  2. Gradle property androidNdk
  3. ANDROID_NDK_HOME
  4. the NDK the module's Android Gradle plugin uses (android.ndkVersion, else AGP's default)

So in an Android module, an environment variable the user never set beats the NDK the module's own build declares, without any message. The Kotlin code (AGP) and the native libraries (KonanPlugin) can end up on different NDKs.

Worked around in lemcoder/MikroSoundFont#7 by pointing ANDROID_NDK_HOME at NDK 28 in the workflows and checking alignment before publishing.

Proposal

In a module with the Android Gradle plugin, rank AGP's NDK above ANDROID_NDK_HOME:

  1. DSL
  2. Gradle property
  3. AGP's NDK (when AGP is applied and that NDK is installed)
  4. ANDROID_NDK_HOME

Explicit choices made in the build (DSL, Gradle property, android.ndkVersion) then win over ambient machine state, and ANDROID_NDK_HOME stays the fallback for modules without AGP.

At minimum, log a warning when ANDROID_NDK_HOME is used and differs from AGP's NDK, naming both paths, and show the source in konanConfig output (it already records ConfigSource).

Acceptance

  • A test with AGP applied and ANDROID_NDK_HOME set to a different NDK resolves androidNdk to AGP's NDK (or, for the warning-only variant, emits the warning).
  • README/CLAUDE.md document the precedence.

Activity

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