Search code examples
javaandroidandroid-studiogradleandroid-ndk

How to set NDK path in Gradle build scripts when using CMake?


So all the reading I've done online says to set ndk.dir in the ANT build properties file to fix the "NDK not configured" error I'm getting from Gradle, but obviously I can't do that because I'm not using ant, I'm using Gradle+CMake.

Below is my gradle script. I'm still very new to this, I'm just trying to figure things out as I go. I got the java piece building fine in Gradle but at this point I am not able to integrate CMake.

apply plugin: 'com.android.library'

android {
    compileSdkVersion 17
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 17

        ndk {
            moduleName "UI"
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    lintOptions {
        abortOnError false
    }

    externalNativeBuild {
        cmake {
            path '../../CMakeLists.txt'
        }
    }
}

Where can I specify the NDK path? I have an environment variable defined named ANDROID_NDK. CMake 3.7 uses this to hunt down the location of the NDK already. Why isn't the android gradle script using it? What is the proper way since I'm not using ant?

Note: I'm trying to get things building on the command line first outside of Android Studio via gradle build command. The error I get:

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':Core:UI'.
> NDK not configured.
Download it with SDK manager.)

Solution

  • You can specify the path to the NDK in Android Studio by selecting the File->Project Structure menu item.

    You should then see the Project Structure settings dialog where you can specify the NDK location.

    The value you enter here will modify the ndk.dir value in the local.properties file, which you can see in the background in the image below:

    enter image description here