目前正在运行Android Studio 1.1.0。安装NDK并添加指向build.gradle文件的链接。构建项目将提供以下文本的跟踪。
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
Android Studio不支持NDK r10d吗?
答案 0 :(得分:10)
当前的NDK支持仍适用于简单项目(即不依赖于其他NDK预构建库的C / C ++源代码),包括使用最新的r10d NDK时。
但它确实有限,正如警告所说,它已被弃用,是的。
我建议您只需停用它,然后直接调用ndk-build。通过这种方式,您可以保留经典的Android.mk/Application.mk配置文件,并从项目中调用ndk-build仍然可以像使用eclipse项目一样工作:
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 :(得分:1)
我使用以下方法构建ndk-build
绝对路径:
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
}
用作:
commandLine getNdkBuildExecutablePath(), '-C', ...
答案 2 :(得分:1)
现在Canary频道的Android Studio 1.3完全支持NDK。试试吧。参考:http://tools.android.com/download/studio/canary/latest