Nanfeng

Notes on software development, code, and curious ideas

Installing the Android NDK on macOS

Android game projects often require a specific NDK release. Use the version declared by the project’s build scripts rather than automatically choosing the newest one.

Install through Android Studio

Open Settings → Languages & Frameworks → Android SDK → SDK Tools, enable NDK (Side by side), select Show Package Details, and choose the required version. Install CMake as well if the project uses it.

The command-line equivalent is:

1
2
sdkmanager --list | grep 'ndk;'
sdkmanager 'ndk;VERSION_REQUIRED_BY_PROJECT'

Side-by-side releases are normally placed under:

1
$ANDROID_SDK_ROOT/ndk/VERSION

Gradle projects should pin the version:

1
2
3
android {
ndkVersion "VERSION_REQUIRED_BY_PROJECT"
}

Shell configuration

On current macOS versions, zsh normally reads ~/.zshrc. Add paths that match your installation:

1
2
3
export ANDROID_SDK_ROOT="$HOME/Library/Android/sdk"
export ANDROID_NDK_HOME="$ANDROID_SDK_ROOT/ndk/VERSION_REQUIRED_BY_PROJECT"
export PATH="$ANDROID_SDK_ROOT/platform-tools:$PATH"

Reload the shell and verify:

1
2
source ~/.zshrc
test -d "$ANDROID_NDK_HOME" && echo 'NDK found'

Very old projects may require archived releases such as r10e. Prefer official Android archives, verify the checksum, and isolate the old toolchain because it does not include current compiler and security updates.

+