【问题标题】:Execution failed for ':app:ndkBuild'. Process 'command ndk-build.cmd' finished with non-zero exit value 2':app:ndkBuild' 执行失败。进程“命令 ndk-build.cmd”以非零退出值 2 结束
【发布时间】:2017-05-25 06:54:01
【问题描述】:

我已经被这个问题困扰了 2 天,并尝试了 stackoverflow 上给出的所有可能的解决方案。下面是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    sourceSets.main.jni.srcDirs = []
    sourceSets.main.jniLibs.srcDir 'src/main/libs'

defaultConfig {
    applicationId "com.example.anannyauberoi.testingcam"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    ndk {
        moduleName "app"
        cFlags "-std=c++11 -fexceptions"
        ldLibs "log"
        stl "gnustl_shared"
        abiFilter "armeabi-v7a"
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets { main { jni.srcDirs = []
    res.srcDirs = ['src/main/res']
    jniLibs.srcDirs=['src/main/libs']
} }
//sourceSets.main.jni.srcDirs = []
// disable automatic ndk-build call, which ignore our Android.mk

task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
    commandLine "C:/Users/Anannya-Uberoi/AppData/Local/Android/sdk/ndk-bundle/ndk-build.cmd",
            'NDK_PROJECT_PATH=build/intermediates/ndk',
            'NDK_LIBS_OUT=src/main/jniLibs',
            'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
            'NDK_APPLICATION_MK=src/main/jni/Application.mk'
}
tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

tasks.all { task ->
    if (task.name.startsWith('compile') && task.name.endsWith('Ndk')) {
        task.enabled = false
    }
}

// call regular ndk-build(.cmd) script from app directory

}
    //Modify the below set of code to the ndk-build.cmd location in your computer.

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile project(':openCVLibrary249')
}

我已经尝试了所有可能的解决方案——删除构建文件夹中的 obj 文件夹,试图通过设置 sourceSets.main 来避免自动调用 Android.mk,试图避免调用 compileDebugNdk 任务。我也没有任何 cmake.txt 文件。我似乎无法克服这个问题。

我使用过 Android Studio 2.3.2 和 2.1.1,但问题一直存在。

任何帮助将不胜感激。

【问题讨论】:

  • "Execution failed for ':app:ndkBuild'. Process 'command ndk-build.cmd' finished with non-zero exit value 2" 就是这样吗?仅此而已?
  • @pskink 确切的错误是Error:Execution failed for task ':app:cleanNative'. > Process 'command 'C:\Users\Anannya-Uberoi\AppData\Local\Android\Sdk\ndk-bundle/ndk-build.cmd'' finished with non-zero exit value 2。这是我得到的唯一错误。
  • 然后从命令行运行gradlew - 它位于项目的顶层文件夹
  • 在 Android Studio 中打开终端(Windows 中为 Alt+F12)。然后运行cd app/src/main/jni 然后运行ndk-build V=1。这将告诉您构建失败的确切原因。
  • 或者,从终端,您可以从应用的主目录gradlew --infogradlew --stacktracegradlew --debug 运行

标签: android gradle android-ndk android-gradle-plugin opencv4android


【解决方案1】:

你应该使用最新的 Android Studio,2.3.2 是可以的。它在 android gradle 插件中集成了 externalNativeBuild,因此您不需要自定义 gradle 任务的技巧。

我无法实际测试下面的 build.gradle 脚本,所以请原谅我的任何拼写错误:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"

defaultConfig {
    applicationId "com.example.anannyauberoi.testingcam"
    minSdkVersion 15
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    externalNativeBuild {
        ndkBuild {
            targets "app"
            cppFlags "-std=c++11 -fexceptions"
            arguments "APP_STL=gnustl_shared"
            abiFilters "armeabi-v7a"
        }
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets { main { 
  res.srcDirs = ['src/main/res']
} }

externalNativeBuild {
    ndkBuild {
        path "src/main/jni/Android.mk"
    }
}

    //Modify the below set of code to the ndk-build.cmd location in your computer.

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile project(':openCVLibrary249')
}

【讨论】:

    【解决方案2】:

    我去了:

    C:\Users\Dev\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd
    

    目录和ndk-build.cmd我按

    右键单击>编辑和更改 cmd 文件:

    @echo off
    %~dp0\build\ndk-build.cmd %*
    

    @echo off
    THAT works for me
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 2018-12-05
      • 2015-10-17
      • 2021-03-08
      相关资源
      最近更新 更多