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
}