How to fix Error:(158) Android NDK: Aborting. .Stop. (ndk-build.cmd'' finished with non-zero exit value 2)

我是研究僧i 提交于 2019-12-25 09:27:33

问题


I want to develop an android application about Auto crop in a scanned image or photo by using OpenCV. I found an open source application name "android-opencv-scan-doc" on github. After I downloaded, try to build and run this project on my computer. The application can not start and gives the following exception:

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
C:\Users\user\AppData\Local\Android\sdk\ndk-bundle\build\core\build-local.mk
Error:(158) *** Android NDK: Aborting.    .  Stop.
Error:Execution failed for task ':app:ndkClean'.
> Process 'command 'C:\Users\user\AppData\Local\Android\Sdk\ndk-bundle/ndk-build.cmd'' finished with non-zero exit value 2
Information:BUILD FAILED

code in app build.gradle is:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.example.yangyao.android_opencv"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"

    ndk {
        moduleName "OpenCV"
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets.main.jni.srcDirs = []
sourceSets.main.jniLibs.srcDirs = ['src/main/libs','src/main/jniLibs']


task ndkBuild(type: Exec, description: 'Compile JNI source with NDK') {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkDir = properties.getProperty('ndk.dir')

    if (org.apache.tools.ant.taskdefs.condition.Os.isFamily(org.apache.tools.ant.taskdefs.condition.Os.FAMILY_WINDOWS)) {
        commandLine "$ndkDir/ndk-build.cmd", '-C', file('src/main/jni').absolutePath
    } else {
        commandLine "$ndkDir/ndk-build", '-C', file('src/main/jni').absolutePath
    }
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

task ndkClean(type: Exec, description: 'Clean NDK Binaries') {
    Properties properties = new Properties()
    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    def ndkDir = properties.getProperty('ndk.dir')

    if (org.apache.tools.ant.taskdefs.condition.Os.isFamily(org.apache.tools.ant.taskdefs.condition.Os.FAMILY_WINDOWS)) {
        commandLine "$ndkDir/ndk-build.cmd",'clean', '-C', file('src/main/jni').absolutePath
    } else {
        commandLine "$ndkDir/ndk-build",'clean', '-C', file('src/main/jni').absolutePath
    }
}

clean.dependsOn 'ndkClean'
}

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

So what should i do? I do not know how to deal with them. Thanks in advance.


回答1:


First, make sure you have the ndk path setup in Project Structure dialog.

If this is not the issue, try to debug ndkClean task, as this is the one failing the build. You can make a more informative gradle build log by adding --stacktrace --debug in the Command-line Options text box on the compiler section in the Settings dialog, or try to go over the lines in this task and find the problematic one.




回答2:


Just remove the white space from the project path and try to use new NDK (android-ndk-r10e-windows-x86_64) it works fine for me




回答3:


I check lots off task but nothing working. and I already have NDK install for other project. but after changing project location solve my issue. if you face issue will be try this.



来源:https://stackoverflow.com/questions/41944138/how-to-fix-error158-android-ndk-aborting-stop-ndk-build-cmd-finished-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!