cutieso
cutieso

Reputation: 47

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.

Upvotes: 5

Views: 2430

Answers (2)

Krasimir Topchiyski
Krasimir Topchiyski

Reputation: 23

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

Upvotes: 1

ismail ateş
ismail ateş

Reputation: 19

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

Upvotes: 1

Related Questions