在SO上提出了同样的错误问题,但他们的解决方案对我不起作用。我自己无法理解,因此我需要帮助。这是我的build.gradle
:
apply plugin: 'com.android.application'
def VUFORIA_SDK_DIR = '../../..'
def JAR_DIR = 'build/java/vuforia'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "src/main/libs"
}
defaultConfig {
applicationId "com.qualcomm.QCARSamples.ImageTargets"
minSdkVersion 8
targetSdkVersion 22
versionCode 200
versionName "5.0"
}
archivesBaseName = rootProject.projectDir.getName()
buildTypes {
release {
minifyEnabled false
ndk {
abiFilters "armeabi-v7a"
}
}
debug {
minifyEnabled false
debuggable true
ndk {
abiFilters "armeabi-v7a"
}
}
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
println('compiling jni code with ndk-build...')
def ndkDir = android.ndkDirectory
if (System.properties['os.name'].toLowerCase().contains('windows')) {
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath
// Additional ndk-build arguments, such as NDK_DEBUG, can be provided here
} else {
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath
// Additional ndk-build arguments, such as NDK_DEBUG, can be provided here
}
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
if (System.properties['os.name'].toLowerCase().contains('windows')) {
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath,
'clean'
} else {
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'clean'
}
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
}
dependencies {
compile files("$VUFORIA_SDK_DIR/$JAR_DIR/Vuforia.jar")
}
Gradle构建始终因此错误而失败:
错误:任务':app:buildNative'的执行失败。 启动进程'command'null / ndk-build''
时出现问题
可能是什么原因?
答案 0 :(得分:3)
我在这里阅读你的内容如下:
@Deprecated
可能会返回null值。我看到的另一个选择是
def ndkDir = android.ndkDirectory
未正确引用您的ndkDir变量,并且您的commandLine执行失败。
commandLine "$ndkDir/ndk-build",
与这两种理论很吻合。
尝试确保在尝试与ndkDir对齐时和/或在commandLine命令之前将变量转换为字符串时不会返回空值。