Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not import the OpenCV Library in Android Studio

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).

Image showing the problem

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.

like image 405
cutieso Avatar asked Nov 06 '22 05:11

cutieso


2 Answers

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.

How to add module dependency

like image 188
ismail ateş Avatar answered Nov 09 '22 13:11

ismail ateş


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

like image 33
Krasimir Topchiyski Avatar answered Nov 09 '22 13:11

Krasimir Topchiyski