java Android Studio 中的 ndk.dir 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28865416/
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-11-02 14:18:50  来源:igfitidea点击:

ndk.dir error in Android Studio

javaandroidopencvandroid-studioandroid-ndk

提问by user3504563

I was trying to use opencv library, so I imported one of its projects in Android Studio and when I tried to run it I got this error:

我试图使用 opencv 库,所以我在 Android Studio 中导入了它的一个项目,当我尝试运行它时,我收到了这个错误:

Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'. NDK not configured. Download the NDK from http://developer.android.com/tools/sdk/ndk/.Thenadd ndk.dir=path/to/ndk in local.properties. (On Windows, make sure you escape backslashes, e.g. C:\ndk rather than C:\ndk)

错误:任务 ':openCVSamplefacedetection:compileDebugNdk' 的执行失败。未配置 NDK。从http://developer.android.com/tools/sdk/ndk/下载 NDK 。然后在 local.properties 中添加 ndk.dir=path/to/ndk。(在 Windows 上,确保您转义反斜杠,例如 C:\ndk 而不是 C:\ndk)

So I downloaded the ndk and I addes this line to the local.properties file where it became:

所以我下载了 ndk 并将这一行添加到 local.properties 文件中,它变成了:

sdk.dir=C\:\Users\skoon\AppData\Local\Android\sdk
ndk.dir=C\:\Users\skoon\AppData\Roaming\IDM\android-ndk-r10d

but I still got this error which I didn't understand:

但我仍然遇到这个我不明白的错误:

Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'. com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Users\skoon\AppData\Roaming\IDM\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android-14 NDK_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj NDK_LIBS_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\lib APP_ABI=all Error Code: 2 Output: make.exe: *** No rule to make target 'C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni', needed by `C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\obj/local/arm64-v8a/objs/detection_based_tracker/C_\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.o'. Stop.

错误:任务 ':openCVSamplefacedetection:compileDebugNdk' 的执行失败。com.android.ide.common.internal.LoggedErrorException:无法运行命令:C:\Users\skoon\AppData\Roaming\IDM\android-ndk-r10d\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users \skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\Android.mk APP_PLATFORM=android- 14 NDK_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\ obj NDK_LIBS_OUT=C:\Users\skoon\Downloads\Compressed\OpenCV-2.4.10-android-sdk\OpenCV-2.4。4.10-android-sdk\samples\face-detection\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.o'。停止。

I didn't change anything in the code, so what should I do? do I need to change or add any variables to point to the ndk?

我没有更改代码中的任何内容,那我该怎么办?我需要更改或添加任何变量来指向 ndk 吗?

P.S. This is my first time trying to build Android application so I don't have any experience.

PS 这是我第一次尝试构建 Android 应用程序,所以我没有任何经验。

Thank you in advance.

先感谢您。

UPDATE:

更新:

To import the project I just used import project from file, then I synced the gardle, and run the project. the package that I downloaded from opencv was the Android one, and I tried to use the face detection sample. when I run it I got the error above.

为了导入项目,我刚刚使用了从文件导入项目,然后我同步了 gardle,并运行了该项目。我从opencv下载的包是Android的,我尝试使用人脸检测示例。当我运行它时,我收到了上面的错误。

采纳答案by Ha Dang

You need to setup OpenCV librairies for your project. You can follow the instruction here.

您需要为您的项目设置 OpenCV 库。您可以按照此处的说明进行操作。

回答by Shyam Kumar

Install NDK in your SDK manager, if you already installed open app's "build.gradle" replace these lines

在您的 SDK 管理器中安装 NDK,如果您已经安装了打开的应用程序的“build.gradle”,请替换这些行

sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/', 'src/main/jni/'] } }

to

sourceSets.main { jniLibs.srcDir 'src/main/jniLibs' // mention your JNI lib path(where ".so" files contains) jni.srcDirs = [] //disable automatic ndk-build call }

sourceSets.main { jniLibs.srcDir 'src/main/jniLibs' // mention your JNI lib path(where ".so" files contains) jni.srcDirs = [] //disable automatic ndk-build call }

I'm tried to configure OpenCV and its fixed

我试图配置 OpenCV 及其固定

回答by quanhua92

OpenCV sample projects haven't support gradle officially. I think it will be easier if you start a new project and configure it to work as in examples. I have implemented a tutorial project using Android Studio + NDK + OpenCV. You may have a look. https://github.com/quanhua92/NDK_OpenCV_AndroidStudio

OpenCV 示例项目尚未正式支持 gradle。我认为如果您开始一个新项目并将其配置为像示例中那样工作会更容易。我已经使用 Android Studio + NDK + OpenCV 实现了一个教程项目。你可以看看。https://github.com/quanhua92/NDK_OpenCV_AndroidStudio