任务':app:compileDebugNdk'的执行失败无法运行

时间:2023-03-17
本文介绍了任务':app:compileDebugNdk'的执行失败无法运行此命令ndk-build.cmd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误:任务 ':app:compileDebugNdk' 执行失败.

<块引用>

com.android.ide.common.internal.LoggedErrorException:无法运行命令:C:Program FilesADTsdkandroid-ndk dk-build.cmd NDK_PROJECT_PATH=null

错误代码:1

这是我在 android studio 上尝试对我的项目运行 make 时得到的输出.我在安卓工作室 1.0sdk 构建工具 24.0,但针对 API 14

这就是我的 Android.mk 文件的样子

 LOCAL_PATH := $(call my-dir)包括 $(CLEAR_VARS)LOCAL_MODULE := 主要LOCAL_SRC_FILES := Main.cppLOCAL_LDLIBS := -llog -ljnigraphics -lz -landroidLOCAL_SHARED_LIBRARIES := libavformat libavcodec libswscale libavutil包括 $(BUILD_SHARED_LIBRARY)$(调用导入模块,ffmpeg/android/arm)

这就是我的 application.mk 文件的样子

APP_ABI := armeabi#APP_ABI := armeabi-v7aAPP_PLATFORM := android-14

解决方案

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

表示 gradle android 插件正在尝试调用 ndk-build 本身来编译您的源代码.您应该在日志窗口中获得比错误代码更多的详细信息.

无论如何,目前它使用自动生成的 Makefile 执行此操作并忽略您的,因为您需要集成 ffmpeg,因此无法正常工作.

要克服这个问题,您应该禁用插件的自动 ndk 集成,并使其使用标准 libs 位置来获取您的 .so 文件:

sourceSets.main {jniLibs.srcDir 'src/main/libs'jni.srcDirs = []//禁用自动 ndk-build 调用}

从那里你可以自己调用 ndk-build,或者让 gradle 为你调用它:

import org.apache.tools.ant.taskdefs.condition.Os//从 app 目录调用常规 ndk-build(.cmd) 脚本任务 ndkBuild(类型:执行){如果(Os.isFamily(Os.FAMILY_WINDOWS)){命令行 'ndk-build.cmd', '-C', file('src/main').absolutePath} 别的 {命令行'ndk-build','-C',文件('src/main').absolutePath}}tasks.withType(JavaCompile) {编译任务->compileTask.dependsOn ndkBuild}

有关为什么这一切的更多信息,您可以查看此 gist 和我的 博文.

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

com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:Program FilesADTsdkandroid-ndk dk-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.

这篇关于任务':app:compileDebugNdk'的执行失败无法运行此命令ndk-build.cmd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:删除了 Eclipse Juno ADT 插件 NDK 路径? 下一篇:C++ ifstream.getline() 明显慢于 Java 的 BufferedReader.r

相关文章

最新文章