Java – failed task ‘: app: compiledebugndk’ cannot run this command NDK build cmd
Error:Execution Failed for task ':app:compileDebugNdk'.
Error:Execution Failed for task ':app:compileDebugNdk'.
Error Code: 1
This is the output I get when I run make on my project on Android studio I built the tool 24.0 in Android Studio 1.0 SDK, but for API 14
This is my android MK file
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 my application MK file
APP_ABI := armeabi #APP_ABI := armeabi-v7a APP_PLATFORM := android-14
Solution
Error: failed task ': app: compiledebugndk'
This means that the Android plugin is trying to call NDK build to compile the source code You should get more details than the error code in the log window
In any case, it currently uses an automatically generated makefile and ignores your because you need to integrate ffmpeg and can't work
To overcome this problem, you should disable the automatic NDK integration of the plug-in and make it available using the standard LIBS location So file:
sourceSets.main { jniLibs.srcDir 'src/main/libs' jni.srcDirs = [] //disable automatic ndk-build call }
From there, you can call NDK to build yourself, or ask gradle to call 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',file('src/main').absolutePath } } tasks.withType(JavaCompile) { compileTask -> compileTask.dependsOn ndkBuild }
For more information about why all this is happening, you can check this gist and my blog post