6

Currently running Android Studio 1.1.0. Installed NDK and added the link to the build.gradle file. Building the project gives a trace with the following text.

WARNING [Project: :app] Current NDK support is deprecated.  Alternative will be provided in the future.

android-ndk-r10d\ndk-build.cmd'' finished with non-zero exit value 1

Is NDK r10d unsupported by Android Studio?

JGPhilip
  • 1,388
  • 17
  • 19
  • 1
    possible duplicate of [Android studio, gradle and NDK](http://stackoverflow.com/questions/16667903/android-studio-gradle-and-ndk) – Dan Albert Feb 25 '15 at 07:10

3 Answers3

10

The current NDK support is still working for simple projects (ie. C/C++ sources with no dependency on other NDK prebuilt libraries), including when using the latest r10d NDK.

But it's really limited, and as the warning says, it's deprecated, yes.

What I recommend to do is to simply deactivate it, and make gradle call ndk-build directly. This way you can keep your classic Android.mk/Application.mk configuration files, and calling ndk-build from your project will still work the same as with an eclipse project:

import org.apache.tools.ant.taskdefs.condition.Os

...

android {  
  ...
  sourceSets.main {
        jniLibs.srcDir 'src/main/libs' //set .so files location to libs instead of jniLibs
        jni.srcDirs = [] //disable automatic ndk-build call
    }

    // add a task that calls regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('src/main').absolutePath
        }
    }

    // add this task as a dependency of Java compilation
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }
}
ph0b
  • 14,353
  • 4
  • 43
  • 41
1

I use the method below to construct the ndk-build absolute path:

def getNdkBuildExecutablePath() {
    File ndkDir = android.ndkDirectory
    if (ndkDir == null) {
        throw new Exception('NDK directory is not configured.')
    }
    def isWindows = System.properties['os.name'].toLowerCase().contains('windows')
    def ndkBuildFile = new File(ndkDir, isWindows ? 'ndk-build.cmd' : 'ndk-build')
    if (!ndkBuildFile.exists()) {
        throw new Exception(
            "ndk-build executable not found: $ndkBuildFile.absolutePath")
    }
    ndkBuildFile.absolutePath
}

Used as:

commandLine getNdkBuildExecutablePath(), '-C', ...
Joe Bowbeer
  • 3,574
  • 3
  • 36
  • 47
1

Now Android Studio 1.3 at Canary channel fully supports NDK. Try it. Reference: http://tools.android.com/download/studio/canary/latest

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
  • 1
    The one whose release notes say "Sorry, this build does not yet contain the C/C++ support"? Unless that's a different feature, that sounds like it refers to NDK – kaay Jul 03 '15 at 13:45