wanipook
wanipook

Reputation: 33

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

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.

Upvotes: 0

Views: 3246

Answers (3)

AbuQauod
AbuQauod

Reputation: 919

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

Upvotes: 1

Md Tariqul Islam
Md Tariqul Islam

Reputation: 2804

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.

Upvotes: 0

yakobom
yakobom

Reputation: 2711

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.

Upvotes: 0

Related Questions