Ask Your Question
0

Importing OpenCV 4.X android SDK module into Android Studio

asked 2019-11-27 23:50:27 -0600

rtrahms gravatar image

updated 2019-12-10 01:08:04 -0600

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

edit retag flag offensive close merge delete

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 ( 2020-09-12 05:35:41 -0600 )edit

3 answers

Sort by ยป oldest newest most voted
2

answered 2019-11-28 08:50:34 -0600

Akhil Patel gravatar image

updated 2019-11-29 01:00:06 -0600

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.

edit flag offensive delete link more

Comments

1

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

Akhil Patel gravatar imageAkhil Patel ( 2019-11-29 00:29:51 -0600 )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 ( 2019-11-29 00:45:12 -0600 )edit
1

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

Akhil Patel gravatar imageAkhil Patel ( 2019-11-29 01:00:50 -0600 )edit
0

answered 2020-11-02 15:41:49 -0600

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

edit flag offensive delete link more
0

answered 2020-04-05 03:06:02 -0600

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.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-11-27 23:50:27 -0600

Seen: 8,198 times

Last updated: Nov 30 '19