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

24,763

since you're using Windows, you should call ndk-build.cmd instead of ndk-build, from your ndkBuild task.

To make your gradle file work on windows and unix-compatible systems you can modify your task this way:

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, as you're using ndk-build directly, the ndk will generate your libraries inside the libs folder, so you should uncomment jniLibs.srcDir 'src/main/libs' inside your gradle file, in order for your generated libs to be taken in account.

Share:
24,763
choijuho
Author by

choijuho

Android Novice Programer

Updated on June 29, 2020

Comments

  • choijuho
    choijuho almost 4 years

    enter image description here

    Hi. I'm in Android Studio NDK Build trouble. I've not used native library. just java classes for library use and JNI c or header files. So I've confused how to write gradle file for my project(saskin library ; I'm studying it). Please help me~!

    Error message

    Error:Execution failed for task ':app:buildNative'. A problem occurred starting 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 {
    }