This page shows you how to configure the NDK in your project according to the version of the Android Gradle Plugin (AGP) used by the project.
The steps vary according to the version of AGP used in the project. Find the Android Gradle Plugin version in either of the following locations:
- File > Project Structure > Project menu in Android Studio
- The top-level
build.gradlefile in the project
Select the version below:
AGP version 3.4
You have the following options to configure the NDK:
Do not set any property. Use the command line to install the NDK in the
android-sdk/ndk-bundle/directory.In the
local.propertiesfiles at the root of the Android Studio project, use thendk.dirproperty:ndk.dir = /Users/ndkPath/ndk21 // Point to your own NDK</pre>You can also set this using the Android Studio UI (File > Project Structure > SDK Location > Android NDK location).
Use the
$ANDROID_NDK_HOMEenvironmental variable to set the path to the NDK. Android Studio reads this settings and caches it to the UI andndk.dirat launch.
Install the NDK from the command line
To install the NDK from the command line, do the following:
Use the
sdkmanagertool to view versions of CMake and NDK packages that are available. Similar to other SDK components, the NDK is released through different channels:sdkmanager --list [--channel=channel_id] // NDK channels: 0 (stable), // 1 (beta), or 3 (canary)Pass the
sdkmanagerthe strings for the packages that you want to install. For example, to install CMake or the NDK, use the following syntax:sdkmanager --install ["ndk;major.minor.build[suffix]" | "cmake;major.minor.micro.build"] [--channel=channel_id]
Use the
--channeloption to only install a package if it has been released in a channel up to and including channel_id.
For more information, see sdkmanager.