2

I'm trying to add the OpenCV library to my app, I downloaded the latest version 4.5.2 from SourceForge.

I add it module using File>New>Import Module and selecting OpenCV-android-sdk/sdk/java as all the online instructions suggest.

Then I go Project Structure>Dependencies to add that module as a dependency, but the module I just added doesn't how up. And its crazy cuz in the window behind it you can see that it see’s my added OpenCv module, but it somehow doesn't recognize it as a module that can be depended on. I know I can manually add it in build.gradle, but the end result is not working and I have feeling there’s a correlation between this issue and the bigger problem.

enter image description here

Is there something special the module need to contain in order for Android Studio to see it as a real module that can be depended on?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Siavash
  • 7,583
  • 13
  • 49
  • 69

1 Answers1

2

Turns out that all of the instructions on how to add openCV to Android are out dated. They are all based on an older version of openCV that require you to import the the .../sdk/java subfolder of the sdk you download.

But in the latest openCv download that folder doesn't have a build.gradle file, and thus android Studio auto generates one for it. But this autogenerated build.gradle doesn't have the right settings for the module to work properly and be seen by AS as a depend-able module.

The solution is to import the whole ../sdk folder

Siavash
  • 7,583
  • 13
  • 49
  • 69
  • Do you know any good tutorials to use OpenCV android? How to use classes and stuffs like this. not just adding it to a project – Mohammad Jun 18 '21 at 17:29
  • 1
    I searched for a few months and didnt find any good ones, I just followed the example projects, and created our own library for it which in a few months we will make public – Siavash Jun 21 '21 at 22:43
  • I am also interested in the latest updated OpenCV-Android tutorials. Right now, I am trying to run the accompanying OpenCV-Android samples but I don't know how to load them from within Android Studio. It seems to me the file structures are different. – Second Person Shooter Jul 01 '21 at 04:46