14
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
user3188402
  • 205
  • 1
  • 3
  • 10

4 Answers4

25

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.

ph0b
  • 14,353
  • 4
  • 43
  • 41
  • Thanks so much I got past it but now it can't find my headers that I specified with the LOCAL_C_INCLUDES keyword. Another question for another time I suppose. I will definitely check out your blog , I've learned so much from just reading experienced programmerss blogs. – user3188402 Dec 17 '14 at 02:21
  • You should give an absolute path to LOCAL_C_INCLUDES so it works better. You can do so by starting it by `$(LOCAL_PATH)/`. If you need to specify includes from your modules, you can set `LOCAL_C_EXPORT_C_INCLUDES` on these. – ph0b Dec 17 '14 at 08:34
  • Doing this hides "c" folder from project, so I can't open c files from Android Studio. Is there any workaround? – Parmaia May 22 '15 at 09:42
  • you can execute this step as a part of the regular build process if you use this ```def ndkDir = android.ndkDirectory.getAbsolutePath() commandLine ndkDir + "/ndk-build", '-C', file('src/main').absolutePath``` – C0D3LIC1OU5 Oct 01 '15 at 17:51
20

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.

SpacemanScott
  • 953
  • 9
  • 21
  • 1
    Thanks. @Rushang Prajapati I wish posters would supply **complete** information, rather than dribble it out... So I followed up, without giving in to my desire to criticize them for not being adequate. And Android Studio has such a zoo of files all over the place, poorly documented, it's a prime example of the need to supply complete info. – SpacemanScott Feb 06 '16 at 14:38
  • Doesn't work for me. – Vakas May 31 '23 at 04:57
0

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')
}
Manthan Patel
  • 1,784
  • 19
  • 23
0

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.

Manaslu
  • 228
  • 1
  • 13