Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDK support deprecated for Android Studio 1.1.0

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?

like image 613
JGPhilip Avatar asked Feb 25 '15 06:02

JGPhilip


1 Answers

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
    }
}
like image 181
ph0b Avatar answered Sep 21 '22 03:09

ph0b