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?

1

3 Answers 3

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
    }
}
1
  • Whats that "absolutePath"?
    – dharmendra
    Commented Mar 2, 2015 at 10:49
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', ...
1

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

1
  • 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
    Commented Jul 3, 2015 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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