4

I'm developing (with Android Studio) an Android app that uses OpenCV 3.1.0. I'm using async OpenCV initialization. My questions is: do I need to copy OpenCV native libs (OpenCV-android-sdk/sdk/native/libs) to my jniLibs directory (app/src/main/jniLibs)?

In all the tutorials that I've read about how to setup OpenCV in Android Studio they copy the libraries. But, as I'm using OpenCV manager to access OpenCV libraries externally installed in the device (not static initialization), I think I don't need to copy the libraries. Am I right?

Thanks for your help.

3

2 Answers 2

4

After some time working with OpenCV for Android, I can give an answer to my question:

Async initialization

If you are using async initialization with OpenCV Manager you don't need to copy the native OpenCV libs to your project. Because you are using OpenCV Manager for that:

OpenCV Manager is an Android service targeted to manage OpenCV library binaries on end users devices. It allows sharing the OpenCV dynamic libraries between applications on the same device.

More info: OpenCV Manager docs.

Static initialization

According to this approach all OpenCV binaries are included into your application package (this approach is deprecated for the production code).

App without JNI part:
You have to copy the contents of sdk/native/libs into your project directory to folder app/src/main/jniLibs.

App with JNI part:
You need to modify your Android.mk file. After that the OpenCV libraries will be copied to your application jniLibs folder during the JNI build.

More info: Static Initialization docs.

6
  • Would suggest having a look at using CMake native build tool & CMakeLists.txt build script rather than the older ndk-build build tool and Android.mk as of Android Studio version 2.2.* ndk-build is deprecated. See official documentation for further information: tools.android.com/tech-docs/new-build-system/… Nov 2, 2016 at 19:25
  • @Kevin I'll take a look and update the answer. The app that I'm working on at the moment doesn't have a JNI part, so I'm not very familiar with it. Thank you very much for your suggestion. Nov 2, 2016 at 20:02
  • Are you using correct terminology here? Yours which is "Async initialization" seems to be inappropriate because you are comparing it with "static initialization". Probably you want to say "Dynamic initialization", right? Mar 9, 2018 at 14:12
  • I'm using the terminology used in the official docs. You use OpenCV Manager (external app) to access OpenCV libraries externally installed in the target system. When you call OpenCVLoader.initAsync() you define OnManagerConnected callback that is called when initialisation finishes. Mar 9, 2018 at 14:59
  • docs.opencv.org/3.0-beta/doc/tutorials/introduction/… has setup instruction sections for Application Development with Async Initialization , Application Development with Static Initialization (both with and without JNI in your code) , and Native/C++
    – WillC
    Apr 24, 2018 at 13:12
0

Yes you will be needing to copy the contents of sdk/native/libs for OpenCV into the apps jniLibs directory if you usinf NDK, the java based classes are just a `wrapper to the OpenCV native libraries to make it easier for you to work with OpenCV.

See further official documentation at link provided below: http://docs.opencv.org/2.4/doc/tutorials/introduction/android_binary_package/O4A_SDK.html

5
  • After one month working with OpenCV in Android, I have corroborated my hypothesis: No, you don't need to include the native libs if you are using async initialization, because you are using OpenCV Manager for that. But thank you for your answer. Nov 2, 2016 at 13:59
  • @DavidMiguel Thanks David! thats really enlightening. Would I would need to use c++ late-binding? Did not know the exact purpose of the OpenCV Manager. Side note: I was thinking today if there was a way to do away with a user downloading the OpenCV manager app for OpenCV to work within your app, as this might put the user off from downloading your app. I am day 2 in NDK development and there is tons to learn that I am really excited about. Nov 2, 2016 at 14:24
  • To anyone who may stumble across this comment thats new to NDK development and OpenCV. I hope @DavidMiguel comment and the one below helps you out. A lot of the learning I personally experienced is to differentiate between the deprecated toolchains, compilers used for NDK development, and a lot of the information you will find on the internet is out dated including samples. This can be good or bad depending on the project/IDE, toolchains etc. that you are working with. I often stray away from the official documentation but for NDK development currently its a best source to start off with. Nov 2, 2016 at 14:28
  • In my opinion using OpenCV Manager might slightly decrease the user experience, but it gives you some relevant benefits (your app is around 40MB smaller, OpenCV Manager installs optimized binaries for the user hardware, OpenCV Manager is supposed to keep OpenCV libs updated and if the user has other apps that use OpenCV the OpenCV libs are shared). About the official documentation is really a pain in the neck, I've spent hours and hours trying to find updated articles... Thanks for your advices. Nov 2, 2016 at 19:57
  • @DavidMiguel Anytime David and well noted, there is definitely benefits to having the OpenCV Manager app installed on your device as you have pointed out, thanks. I am also experiencing the same issue of lack of newer Android samples/tutorials using OpenCV official documentation. and spend hours looking at all kinds of other documentation/samples to either find its deprecated or not what I really need now. All the best with your OpenCV journey Nov 2, 2016 at 20:43

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.