NDKBuild失败

我无法让我的NDK在Android Studio中正确编译。 每当我尝试运行编译我收到以下错误。

错误:任务“:app:ndkBuild”的执行失败。 启动过程中发生了一个问题'command'ndk-build.cmd''

我有以下设置

在这里输入图像说明

而我的build.gradle文件如下。

import org.apache.tools.ant.taskdefs.condition.Os apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "edu.uky.cs.www.diagramaphone" minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" sourceSets.main{ jniLibs.srcDir 'src/main/libs' jni.srcDirs = [] //disable automatic ndk-build call } project.ext.versionCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3, 'mips':5, 'mips64':6, 'x86':8, 'x86_64':9] //versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-* android.applicationVariants.all { variant -> // assign different version code for each output variant.outputs.each { output -> output.versionCodeOverride = project.ext.versionCodes.get(output.getFilter(com.android.build.OutputFile.ABI), 0) * 1000000 + defaultConfig.versionCode } } // 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 } //ndk { // moduleName "shape-detect" //cFlags "-DANDROID_NDK -D_DEBUG DNULL=0" // Define some macros //ldLibs "EGL", "GLESv3", "dl", "log" // Link with these libraries! //stl "stlport_shared" // Use shared stlport library //} } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:21.0.3' compile project(':libraries:tess-two') compile project(':libraries:opencv') } 

在这一点上,我失去了什么是错的。 我跟着几个教程来尝试设置NDK正常工作,但我不断收到我上面显示的错误。 任何人都可以在这里提供一些反馈,我需要做什么才能让NDK编译?

编辑:这是发生的整个消息。

 Information:Gradle tasks [:app:assembleDebug] :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:compileDebugNdk UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild UP-TO-DATE :libraries:opencv:compileLint :libraries:opencv:copyReleaseLint UP-TO-DATE :libraries:opencv:mergeReleaseProguardFiles UP-TO-DATE :libraries:opencv:preBuild UP-TO-DATE :libraries:opencv:preReleaseBuild UP-TO-DATE :libraries:opencv:checkReleaseManifest :libraries:opencv:prepareReleaseDependencies :libraries:opencv:compileReleaseAidl UP-TO-DATE :libraries:opencv:compileReleaseRenderscript UP-TO-DATE :libraries:opencv:generateReleaseBuildConfig UP-TO-DATE :libraries:opencv:generateReleaseAssets UP-TO-DATE :libraries:opencv:mergeReleaseAssets UP-TO-DATE :libraries:opencv:generateReleaseResValues UP-TO-DATE :libraries:opencv:generateReleaseResources UP-TO-DATE :libraries:opencv:packageReleaseResources UP-TO-DATE :libraries:opencv:processReleaseManifest UP-TO-DATE :libraries:opencv:processReleaseResources UP-TO-DATE :libraries:opencv:generateReleaseSources UP-TO-DATE :libraries:opencv:compileReleaseJava UP-TO-DATE :libraries:opencv:processReleaseJavaRes UP-TO-DATE :libraries:opencv:packageReleaseJar UP-TO-DATE :libraries:opencv:compileReleaseNdk UP-TO-DATE :libraries:opencv:packageReleaseJniLibs UP-TO-DATE :libraries:opencv:packageReleaseLocalJar UP-TO-DATE :libraries:opencv:packageReleaseRenderscript UP-TO-DATE :libraries:opencv:bundleRelease UP-TO-DATE :libraries:tess-two:compileLint :libraries:tess-two:copyReleaseLint UP-TO-DATE :libraries:tess-two:mergeReleaseProguardFiles UP-TO-DATE :libraries:tess-two:preBuild UP-TO-DATE :libraries:tess-two:preReleaseBuild UP-TO-DATE :libraries:tess-two:checkReleaseManifest :libraries:tess-two:prepareReleaseDependencies :libraries:tess-two:compileReleaseAidl UP-TO-DATE :libraries:tess-two:compileReleaseRenderscript UP-TO-DATE :libraries:tess-two:generateReleaseBuildConfig UP-TO-DATE :libraries:tess-two:generateReleaseAssets UP-TO-DATE :libraries:tess-two:mergeReleaseAssets UP-TO-DATE :libraries:tess-two:generateReleaseResValues UP-TO-DATE :libraries:tess-two:generateReleaseResources UP-TO-DATE :libraries:tess-two:packageReleaseResources UP-TO-DATE :libraries:tess-two:processReleaseManifest UP-TO-DATE :libraries:tess-two:processReleaseResources UP-TO-DATE :libraries:tess-two:generateReleaseSources UP-TO-DATE :libraries:tess-two:compileReleaseJava UP-TO-DATE :libraries:tess-two:processReleaseJavaRes UP-TO-DATE :libraries:tess-two:packageReleaseJar UP-TO-DATE :libraries:tess-two:compileReleaseNdk UP-TO-DATE :libraries:tess-two:packageReleaseJniLibs UP-TO-DATE :libraries:tess-two:packageReleaseLocalJar UP-TO-DATE :libraries:tess-two:packageReleaseRenderscript UP-TO-DATE :libraries:tess-two:bundleRelease UP-TO-DATE :app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE :app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE :app:prepareDiagramaphoneLibrariesOpencvUnspecifiedLibrary UP-TO-DATE :app:prepareDiagramaphoneLibrariesTessTwoUnspecifiedLibrary UP-TO-DATE :app:prepareDebugDependencies :app:compileDebugAidl UP-TO-DATE :app:compileDebugRenderscript UP-TO-DATE :app:generateDebugBuildConfig UP-TO-DATE :app:generateDebugAssets UP-TO-DATE :app:mergeDebugAssets UP-TO-DATE :app:generateDebugResValues UP-TO-DATE :app:generateDebugResources UP-TO-DATE :app:mergeDebugResources UP-TO-DATE :app:processDebugManifest UP-TO-DATE :app:processDebugResources UP-TO-DATE :app:generateDebugSources UP-TO-DATE :app:ndkBuild FAILED Error:Execution failed for task ':app:ndkBuild'. > A problem occurred starting process 'command 'ndk-build.cmd'' Information:BUILD FAILED Information:Total time: 2.226 secs Information:1 error Information:0 warnings Information:See complete output in console 

Solutions Collecting From Web of "NDKBuild失败"

我遇到了这样的问题。 首先,你必须在应用程序的local.properties中提供你的NDK路径。

例如ndk.dir=/home/user/bin/android_ndk/android-ndk-r10e

然后在我的build.gradle文件中,我调用了ndk build命令。

 commandLine 'ndk-build', '-C', file('src/main/jni').absolutePath 

我会改变它

 commandLine '/home/user/bin/android_ndk/android-ndk-r10e/ndk-build', '-C', file('src/main/jni').absolutePath 

我给了NDK构建的完整路径。 希望它会帮助你。

尝试这个

 commandLine'E:\\Android\\ndk\\ndkbuild.cmd','-C',file('src/main/jni').absolutePath 

用你的ndk路径替换(E:\\ Android \\ ndk \\)。

在android studio中,文件 – >项目结构 – > SDK位置,为您的计算机设置Android NDK位置。

谢谢!

以防万一,如果它帮助别人:

在环境变量中给NDK路径(ndkBuild.cmd所在的父文件夹)也解决了这个问题。

另外,如果你在Linux上,或者@Nooh的Windows的答案,你可以关注@Hayk的答案。

我的观察:

因为,如果我把直接的NDK路径解决了我在Android Studio中的问题,有时又会造成错误,然后我把环境变量的路径和项目构建成功。

在这种情况下,Windows必须把*

  • NDK-build.cmd

*仅适用于Linux环境*

  • NDK建造

*

将ndk路径(C:\ android-ndk-r10e)添加到环境变量(系统变量)中的路径变量的值,这样我的“路径”变量就像这样

设置 – >系统 – >系统设置 – >系统变量 在这里输入图像说明

然后打开命令窗口(cmd)。 用cd命令输入你的项目文件夹的位置,写下“ndk-build”,然后按回车。

  1. 首先你必须在你的项目中检查local.properties文件。 在local.properties中检查ndk路径。 它看起来像这样ndk.dir = D:\\ sdk \\ ndk-bundle

  2. 现在转到build.gradle(模块库)并找到getNdkPath() 。 它会返回连接ndk-build的 ndk路径位置

  3. 改变ndk-build – > ndk-build.cmd 。 它看起来像这样:

    在这里输入图像说明

希望它会帮助你!

接受的答案是好的,但它不工作,因为Android的工具gradle插件2.3: 没有在LibraryPlugin sdkHandler字段更新后生成工具2.3.0 ,所以你需要使用project.android.ndkDirectory.absolutePath变量,即:

 task ndkBuild(type: Exec) { commandLine project.android.ndkDirectory.absolutePath + '/ndk-build', '-C', file('src/main/jni/').absolutePath } 

或者,您可以直接从local.properties中读取ndk.dir: https ://stackoverflow.com/a/32649204/1028256

它容易为Android工作室2.3.3。 只需按照文件 – >项目结构 – > android NDK位置 – >点击下载按钮。 安装ndk后解决我的问题。 在这里输入图像说明