First time here? Check out the FAQ!

Ask Your Question
0

Importing OpenCV 4.X android SDK module into Android Studio

asked Nov 28 '19

rtrahms gravatar image

updated Dec 10 '19

Akhil Patel gravatar image

Android Studio 3.5 OpenCV Android SDK 4.1.1 and 4.1.2 I have followed numerous tutorials importing OpenCV 3.4.X Android SDK modules from source, but have not been able to do the same for OpenCV 4.X Android SDK modules. Has something changed that prevents this import?

The clues: After the import of opencv java folder into the AS project, I first noticed the usual gradle errors (seen in 3.4.X imports) did not appear. Also, when attempting to set up the dependency between the library and the app, I could not (ref: image).

Screenshots of the steps I take to import opencv module from source, then attempt to add the dependency to the app...

image description image description image description image description image description image description image description

<updated with="" solution=""> For some reason, the build.gradle file of the imported OpenCV-4.X Android SDK contains some problematic bits. Once I corrected those, I could set the dependency correctly. Main problem: first line of the OpenCV-4.X build.gradle file was apply plugin: 'com.android.application' when it should be apply plugin: 'com.android.library'. Correcting this and other items in the build.gradle file fixed the issue.

Thanks, Rob

Preview: (hide)

Comments

Thanks, changing gradle file like you said worked for me. Just to be explicit, I had to make two changes first one is as mentioned, change com.android.application to com.android.library and then comment out the ApplicationId line.

roho_324234 gravatar imageroho_324234 (Sep 12 '0)edit

3 answers

Sort by » oldest newest most voted
2

answered Nov 28 '19

Akhil Patel gravatar image

updated Nov 29 '19

First of all you must import your opencv library as a module and than try to add dependency in your app.

file -> new -> import module

also your import module is library not a package or not a project otherwise it will not add in your project dependency. image description. image description. image description. image description. image description. image description. image description.

In above images shows the which path you have to select.

Preview: (hide)

Comments

1

Try above path as your module and than add dependency to your app

Akhil Patel gravatar imageAkhil Patel (Nov 29 '19)edit
1

another thing is that java package does not contain any buid.gradle file i mean java is not gradle build system so that's why it generate an error

Akhil Patel gravatar imageAkhil Patel (Nov 29 '19)edit
1

see above steps shows that i have successfully add opencv dependency in my app

Akhil Patel gravatar imageAkhil Patel (Nov 29 '19)edit
0

answered Nov 2 '0

Do check this answer for more detailed solution: https://medium.com/@kplakshya2015/int...

Preview: (hide)
0

answered Apr 5 '0

HomanH gravatar image

Some zip packages have missed files, such as 4.2.0. I copied the file from 3.4.9: sdk\java; to 4.2.0: sdk\java. These files are: .classpath .project lint.xml project.properties

After you copied the files, you need to edit .project. I change this line: <projectdescription> <name>OpenCV Library - 4.2.0</name>

And you follow the images above by Akhil to import the module and add the dependency in Android Studio.

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Nov 28 '19

Seen: 9,037 times

Last updated: Nov 30 '19