无法在Android Studio中导入OpenCV库。

huangapple go评论154阅读模式
英文:

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"),它们不显示它并且不让我完成这个操作(请查看下面的图像)。

无法在Android Studio中导入OpenCV库。

为什么我无法选择这个库?我正在观看一个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).

无法在Android Studio中导入OpenCV库。

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类。

无法在Android Studio中导入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.

无法在Android Studio中导入OpenCV库。

答案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

huangapple
  • 本文由 发表于 2020年8月5日 04:17:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/63254458.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定