Reputation: 1508
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?
Upvotes: 6
Views: 5887
Reputation: 21766
Now Android Studio 1.3 at Canary channel fully supports NDK. Try it. Reference: http://tools.android.com/download/studio/canary/latest
Upvotes: 1
Reputation: 3861
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', ...
Upvotes: 1
Reputation: 14473
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
}
}
Upvotes: 10