Android Studio NDK Build Error Error: Execution failed for task: app: buildNative '

enter image description here

Hey. I am on Android Studio NDK. I have not used the native library. just java classes to use library and JNI c or header files. So I was confused how to write a gradle file for my project (saskin library, I am looking into it). Please help me!!

Error message

Error: Execution completed for task ': app: buildNative'. There was a problem starting the process "command" C: \ NDK / ndk-build ''

build.gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 8
    buildToolsVersion "21.1.1"

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

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

    defaultConfig {
        applicationId "com.sasken.player"
        minSdkVersion 8
        targetSdkVersion 8

        ndk {
            moduleName "equalizer"
        }
    }

    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath
    }

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

dependencies {
}

      

+3


source to share


1 answer


since you are using Windows you should call ndkBuild ndk-build.cmd

instead ndk-build

from your task.

To make your gradle file work on Windows and unix compatible systems, you can change your task like this:



import org.apache.tools.ant.taskdefs.condition.Os

    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
        } else {
            commandLine 'ndk-build', '-C', file('src/main').absolutePath
        }
    }

      

Also, since you are using ndk-build directly, ndk will generate your libraries inside the libs folder, so you must uncomment jniLibs.srcDir 'src/main/libs'

inside your gradle file for your generated libraries to be taken into account.

+18


source







All Articles