0

Every time i try to build an android app, that uses ndk to run native code, i get the following error:

Error:Gradle: Execution failed for task ':sampleNDK:ndkBuild'.
> Process 'command 'C:\NDK\android-ndk-r10e/ndk-build.cmd'' finished with non-zero exit value 2

I use Intellij with a grandle projekt. I think the error appears in this function in the build.gradle file:

task ndkBuild(type: Exec) {
    def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.getNdkFolder()

    if(org.gradle.internal.os.OperatingSystem.current().windows){
        commandLine "$ndkDir/ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
        //does not work too
        //commandLine "$ndkDir\\ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
    }else{
        commandLine "$ndkDir/ndk-build", 'NDK_PROJECT_PATH=src/main'
    }
}

In fact that i'm using windows, i think the error appears in the if case.

Does anyone know what went wrong or what i can try to avoid the failure?

UPDATE That's the whole build script. Maybe that is helpful.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.1'
    }
}
apply plugin: 'com.android.application'

repositories {
    jcenter()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "de.anmi.android.samplendk"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    sourceSets.main.jni.srcDirs = []
    sourceSets.main.jniLibs.srcDirs = ['src/main/libs']

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

task ndkBuild(type: Exec) {
    // http://stackoverflow.com/questions/28615439/android-gradle-plugin-1-1-0-getndkfolder-not-found-anymore-any-replacement
    def ndkDir = plugins.getPlugin('com.android.application').sdkHandler.getNdkFolder()

    if (org.gradle.internal.os.OperatingSystem.current().windows) {
        commandLine "$ndkDir/ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
//does not work too
//        commandLine "$ndkDir\\ndk-build.cmd", 'NDK_PROJECT_PATH=src/main'
    } else {
        commandLine "$ndkDir/ndk-build", 'NDK_PROJECT_PATH=src/main'
    }
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}
anmi
  • 123
  • 1
  • 1
  • 14
  • Which Android plugin are you using? Maybe it will help you to apply the hybrid solution I proposed for *[define LOCAL_SRC_FILES in ndk{} DSL](http://stackoverflow.com/questions/32636150/define-local-src-files-in-ndk-dsl/32640823#32640823)*. – Alex Cohn Oct 02 '15 at 18:46
  • @AlexCohn I'm not sure if I understood your question correctly. What do you mean with android plugin? – anmi Oct 04 '15 at 19:29
  • 1
    Try to run `ndk-build.cmd` on command line. Does it finish correctly? – Alex Cohn Oct 04 '15 at 20:20
  • Thanks, that was helpful! In the end it was a misspelling at my import statements in the c file.For everyone who has the same problem: If you invoke the `ndk-build.cmd` from command line you get detaild errors. Have a look at this link: [link](https://developer.android.com/ndk/guides/ndk-build.html#ifc) – anmi Oct 05 '15 at 06:59
  • Actually, there is another very valuable tool: invoke `ndk-build V=1` and you will see all compilation/link commands with all parameters as they are actually executed by **ndk-build**! – Alex Cohn Oct 05 '15 at 09:05
  • Thanks, i will try it – anmi Oct 05 '15 at 09:23

0 Answers0