Java 任务 ':app:compileDebugNdk' 执行失败,无法运行此命令 ndk-build.cmd

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27453085/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 04:23:43  来源:igfitidea点击:

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

javaandroidandroid-ndkmakefile

提问by user3188402

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

com.android.ide.common.internal.LoggedErrorException:无法运行命令: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

这是我在 android studio 上尝试在我的项目上运行 make 时得到的输出。我使用的是 android studio 1.0 sdk 构建工具 24.0,但目标是 API 14

this is what my Android.mk file looks like

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

 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

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

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

采纳答案by ph0b

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

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.

意味着 gradle android 插件试图调用 ndk-build 本身来编译你的源代码。您应该获得比日志窗口中的错误代码更多的详细信息。

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

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

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

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

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

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

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

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 gistand my blog post.

有关原因的更多信息,您可以查看此要点和我的博客文章

回答by SpacemanScott

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.

为了帮助搜索此内容但无法弄清楚上述语句的位置的任何人...它位于 {project_name}/app 文件夹下的 build.gradle 中。

Specifically:

具体来说:

{YourApp} / app / build.gradle

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

而不是项目根目录下的 build.gradle。

Place it inside the "defaultConfig" section.

将它放在“defaultConfig”部分中。

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.

希望这个小小的建议可以防止有人花费过多的时间试图找出需要进行哪些更改以及在何处进行更改。

回答by Manthan Patel

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

回答by Piotr Michalski

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.

我今天遇到了这个问题(发布问题 3 年后),并注意到如果 @ph0b 和 @SpacemanScott 的答案不起作用,可能是由于最新手机缺乏 2.xx 支持。然后尝试安装最新的 OpenCV。