2016-03-10 44 views
2

SO上也提出了同樣的錯誤問題,但他們的解決方案對我無效。我自己弄不明白,因此我需要幫助。這裏是我的build.gradle執行失敗的任務':app:buildNative'

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") 
} 

搖籃建立總是失敗,此錯誤:

Error:Execution failed for task ':app:buildNative'. A problem occurred starting process 'command 'null/ndk-build''

可能是什麼原因?

回答

3

我閱讀的你有什麼在這裏是如下:

def ndkDir = android.ndkDirectory 

可能是返回一個空值。我看到的另一個選項是

commandLine "$ndkDir/ndk-build", 

沒有正確引用您的ndkDir變量,並且您的commandLine執行失敗。

Error:Execution failed for task ':app:buildNative'. A problem occurred starting process 'command 'null/ndk-build'' 

與這兩種理論很好地吻合。

嘗試確保您在嘗試對ndkDir進行分級時不會得到空回,和/或在commandLine命令之前將該變量轉換爲字符串。

相關問題