execution failed for task ':app:compileDebugNdk' failed to run this command ndk-build.cmd

Error:Execution failed for task ':app:compileDebugNdk'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Program Files\ADT\sdk\android-ndk\ndk-build.cmd NDK_PROJECT_PATH=null

Error Code:
1

this is the output I get when trying to run a make on my project on android studio.
I’m on android studio 1.0
sdk build tools 24.0 but targeting API 14

this is what my Android.mk file looks like

 LOCAL_PATH := $(call my-dir)

 include $(CLEAR_VARS)

 LOCAL_MODULE    := Main
 LOCAL_SRC_FILES := Main.cpp
 LOCAL_LDLIBS := -llog -ljnigraphics -lz -landroid
 LOCAL_SHARED_LIBRARIES := libavformat libavcodec libswscale libavutil

 include $(BUILD_SHARED_LIBRARY)
 $(call import-module,ffmpeg/android/arm)

this is what my application.mk file looks like

APP_ABI := armeabi
#APP_ABI := armeabi-v7a
APP_PLATFORM := android-14

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Error:Execution failed for task ':app:compileDebugNdk'.

means that the gradle android plugin is trying to call ndk-build itself to compile your sources. You should get more details than the error code in your log window.

Anyway, currently it does this using an auto-generated Makefile and ignores yours, which can’t work since you need to integrate ffmpeg.

To overcome this, you should disable the plugin’s automatic ndk integration and make it use the standard libs location to get your .so files:

sourceSets.main {
    jniLibs.srcDir 'src/main/libs'
    jni.srcDirs = [] //disable automatic ndk-build call
}

from there you can call ndk-build yourself, or make gradle call it for you:

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
    }
}

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

For more information on why all this, you can check this gist and my blog post.

Solution 2

To help anyone who searched this, but can’t figure out where the above statement goes…
It is placed in the build.gradle which is under the {project_name}/app folder.

Specifically:

{YourApp} / app / build.gradle

And not the build.gradle at the root of the project.

Place it inside the “defaultConfig” section.

defaultConfig {
    ....
    sourceSets.main {
        jniLibs.srcDir 'src/main/libs'
        jni.srcDirs = [] //disable automatic ndk-build call
    }

Hopefully, this small advice will prevent someone from spending an excessive amount of time trying to figure out which and where this change needs to be made.

Solution 3

below module:app code work perfectly ..so you can refer this…==>

  apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.3"
    defaultConfig {
        applicationId "com.mnthn.liking"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }


    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jni.srcDirs = ['src/main/jniLibs/']
            jni.srcDirs = []
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile project(':openCVLibrary331')
}

Solution 4

I went through this problem today (3 years after posting question) and noticed that if @ph0b and @SpacemanScott answers don’t work it may be due to lack of 2.x.x support in newest phones. Try to install latest OpenCV then.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply