20

I am trying to build an Android project with Gradle. The project uses native code and thus needs NDK, which I have installed.

However, Gradle fails with the following error:

> NDK not configured. 
  Download it with SDK manager.

Android’s SDK Manager does not list NDK as an option. Besides, I have NDK installed on my box, so the error seems to be that Gradle isn’t finding it.

Most answers assume users to have Android Studio, which I do not have and do not want. Any way to fix this without?

2 Answers 2

15

Most answers assume users to have Android Studio, which I do not have and do not want. Any way to fix this without?

Yes, you don't have to install Android Studio.

For your existing Android project, I expect that you already have local.properties under your root dir of your project. Open and modify there to set your NDK dir. For example, your NDK version is android-ndk-r17b (https://developer.android.com/ndk/downloads/), and you have installed (or unzipped) it in directory /Users/myname/foo/xxx/Android/android-ndk-r17b, then modify this file as below:

ndk.dir=/Users/myname/foo/xxx/Android/android-ndk-r17b 
sdk.dir=/Users/myname/foo/xxx/Android/sdk
2
  • 1
    This answer is useful also if you have Android Studio, and got code from another developer which included their local.properties. You can edit their local.properties and delete the line with ndk.dir that points to their local machine folder, if your Android Studio is already configured with the correct folder on your machine. Then gradle sync and the error would be gone. Commented May 26, 2020 at 2:23
  • FYI this is now slightly outdated due to deprecation of the ndk.dir configuration in local.properties. It still works (for now) but the recommended approach is now outlined here for setting this correctly: developer.android.com/studio/…
    – speby
    Commented Feb 17, 2021 at 23:49
11

Make sure you have an environment variable ANDROID_NDK_HOME set and pointing to your NDK install directory. In my case this did the trick:

export ANDROID_NDK_HOME=/home/myself/bin/android-ndk-r10e

You may want to add this to your .bashrc or similar to have the variable inserted at login, or run the command above each time you launch a shell and want to build an NDK project.

As an alternative, if you installed ndk-bundle through sdkmanager, it will be found without an extra environment variable.

1
  • This worked for me. I was using the Linux command line to install a specific build yes | ./sdkmanager --install "ndk;21.0.6113669" and was using NDK_ROOT and NDK_HOME to point to install but the env variable I needed was ANDROID_NDK_HOME. That variable seemed to be set if you do --install ndk-build but that always installs the latest version. I got those versions from ./sdkmanager --list Commented Apr 12, 2020 at 0:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.