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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With