英文:
Could not import the OpenCV Library in Android Studio
问题
我已经下载了Android Studio 4.0.1以及相同版本的OpenCV库。
我创建了一个随机的Java项目,只是为了设置这个库,但当我选择库时(路径是正确的 - "C:\opencv-4.0.1-android-sdk\OpenCV-android-sdk\sdk\java"),它们不显示它并且不让我完成这个操作(请查看下面的图像)。
为什么我无法选择这个库?我正在观看一个YouTube视频(我是新手),那个人看到的情况完全不同。
英文:
I had downloaded the Android Studio 4.0.1 and the same version for OpenCV Library.
I made a random Java project just to set the library, but when I select the library (the path is correct -"C:\opencv-4.0.1-android-sdk\OpenCV-android-sdk\sdk\java") they don't show it and let me finish this action (please see the image below).
Why I can't select the library? I am watching an Youtube video for this (beginner here) and the guy can see it totally different.
答案1
得分: 1
不需要选择库。添加此模块,然后执行以下步骤:
打开项目结构-> 依赖项-> 应用程序-> 添加模块依赖项-> 选择opencv模块。
您现在可以访问opencv类。
英文:
You don't need to select library. Add this module then do this steps:
Open Project Structure-> Dependencies-> app -> Add module dependency-> select opencv module.
You can access opencv classes right now.
答案2
得分: 1
对我来说,导入项目功能也不起作用,但有效的方法是创建一个新的空项目,清除其构件,然后将OpenCV库的构件从OpenCV-android-sdk\sdk\java\文件夹复制到其中。有6个步骤:
- 将AndroidManifest.xml复制到src/main
- 将源代码复制到src/main/java
- 将res文件夹复制到src/main
- 从OpenCV-android-sdk\sdk\native\libs复制libs文件夹到src/main,并将其重命名为jniLibs
- 创建src\main\aidl文件夹并将文件src\main\java\org\opencv\engine\OpenCVEngineInterface.aidl移动到src\main\aidl\org\opencv\engine\文件夹中
- 在build.gradle中通过指定插件将项目设置为库,如 plugins { id 'com.android.library' } 所示
您可以参考以下图片以查看最终项目结构:
项目结构图片
英文:
For me the import project functionality also doesn't work, but what worked is to create a new empty project, clears its artifacts, and copy the OpenCV library artifacts from OpenCV-android-sdk\sdk\java\ folder. There are 6 steps:
- copy AndroidManifest.xml to src/main
- copy sources to src/main/java
- copy res folder to src/main
- copy libs folder from OpenCV-android-sdk\sdk\native\libs to src/main and rename it to jniLibs
- create folder src\main\aidl and move file src\main\java\org\opencv\engine\OpenCVEngineInterface.aidl to folder src\main\aidl\org\opencv\engine\
- in build.gradle set project as library by specifying plugins { id 'com.android.library'}
You can refer to the image in order to see the final project tree:
project structure image
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论