Android Studio 中的 ndk.dir 错误 [英] ndk.dir error in Android Studio
问题描述
我试图使用 opencv 库,所以我在 Android Studio 中导入了它的一个项目,当我尝试运行它时出现此错误:
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:
错误:任务 ':openCVSamplefacedetection:compileDebugNdk' 的执行失败.未配置 NDK.从 http://developer.android.com/tools/sdk/ndk/下载 NDK.然后在local.properties中添加ndk.dir=path/to/ndk.(在 Windows 上,确保您转义反斜杠,例如 C:\ndk 而不是 C:\ndk)
Error:Execution failed for task ':openCVSamplefacedetection:compileDebugNdk'. NDK not configured. Download the NDK from http://developer.android.com/tools/sdk/ndk/.Then add ndk.dir=path/to/ndk in local.properties. (On Windows, make sure you escape backslashes, e.g. C:\ndk rather than C:\ndk)
所以我下载了 ndk 并将这一行添加到 local.properties 文件中:
So I downloaded the ndk and I addes this line to the local.properties file where it became:
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:
错误:任务 ':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.10-android-sdk\samples\face-detection\openCVSamplefacedetection\build\intermediates\ndk\debug\lib APP_ABI=all错误代码:2输出:make.exe: *** 没有规则可以制作目标 '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',需要`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'.停止.
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.
我没有更改代码中的任何内容,那我该怎么办?我是否需要更改或添加任何变量以指向 ndk?
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?
附言这是我第一次尝试构建 Android 应用程序,所以我没有任何经验.
P.S. This is my first time trying to build Android application so I don't have any experience.
提前致谢.
更新:
为了导入项目,我刚刚使用了从文件导入项目,然后我同步了 gardle,并运行了该项目.我从opencv下载的包是Android的,我尝试使用人脸检测示例.当我运行它时,我得到了上面的错误.
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.
推荐答案
您需要为您的项目设置 OpenCV 库.您可以按照此处的说明进行操作.
You need to setup OpenCV librairies for your project. You can follow the instruction here.
这篇关于Android Studio 中的 ndk.dir 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!