':app:ndkBuild'执行失败。进程'命令ndk-build.cmd'以非零退出值2结束 [英] Execution failed for ':app:ndkBuild'. Process 'command ndk-build.cmd' finished with non-zero exit value 2

查看:210
本文介绍了':app:ndkBuild'执行失败。进程'命令ndk-build.cmd'以非零退出值2结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在这个问题上停留了2天,并试用了所有可能的解决方案。下面是我的build.gradle文件:

I have been stuck on this problem for 2 days and have tried out all possible solutions given on stackoverflow. Below is my build.gradle file:

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

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

I have already tried all possible solutions- deleting the obj folder in the build folder, trying to avoid automatic Android.mk call by setting the sourceSets.main, trying to avoid the compileDebugNdk task from getting called. I also do not have any cmake.txt files. I cannot seem to get over the problem.

我已经使用Android Studio 2.3.2和2.1.1,并且问题一直存在于两者中。

I have used Android Studio 2.3.2 and 2.1.1 and the problem has persisted in both of them.

任何帮助都将值得赞赏。

Any help would be appreciated.

推荐答案

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

You should use the latest Android Studio, 2.3.2 is OK. It has integrated externalNativeBuild in android gradle plugin, so you don't need the tricks with custom gradle task.

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

I could not actually test the build.gradle script below, so please forgive me any typos:

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

这篇关于':app:ndkBuild'执行失败。进程'命令ndk-build.cmd'以非零退出值2结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆