sashoalm sashoalm - 1 year ago 529
Android Question

How to integrate OpenCV into Qt Creator Android project

I use Qt Creator to compile an Android application. I needed to integrate OpenCV into it, and it took me half a day to configure it properly, so I want to document the steps I took here, in case somebody else ever has to do it.

Answer Source

Edit: I forgot to mention, but I already had installed OpenCV Manager on my phone when trying to run one of the samples that come with OpenCV-2.4.10-android-sdk, so I don't know if it's needed or not. In any event, keep it in mind, if it fail even after my steps, you might need to download OpenCV Manager (it's available on the Google Store).

Edit 2: I'm using adt-bundle-windows-x86-20140702, android-ndk-r10d, OpenCV-2.4.10-android-sdk, Qt Creator 3.3.0, and my build target is "Android for armeabi-v7a (GCC 4.9, Qt 5.4.0)".

Edit 3: From Daniel Saner's comment:

In OpenCV 3.x, opencv_java has been renamed to opencv_java3. Also, while I didn't look into the specific changes that might have effected this, the workaround regarding that library in the final step seems to no longer be necessary. The app compiles and runs without the ANDROID_PACKAGE_SOURCE_DIR line

First, I downloaded OpenCV-2.4.10-android-sdk, and put into my project directory. It contains static libraries, and link order matters for static libraries for GCC. So you need to order them just so. This is how my .pro file looked in the end ($$_PRO_FILE_PWD_ refers to the project directory):

INCLUDEPATH += "$$_PRO_FILE_PWD_/OpenCV-2.4.10-android-sdk/sdk/native/jni/include"
android {
    LIBS += \


After that the project will compile but it will fail to run with the error

E/AndroidRuntime(11873): java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1891]:   176 could not load needed library '' for '' (load_library[1093]: Library '' not found)

To overcome this, you need to add to your APK, and then manually load it from That's what the ANDROID_PACKAGE_SOURCE_DIR=$$_PRO_FILE_PWD_/android line at the end was for. Now you need to place here:


You can get from the Android target build directory, in my case the full path was c:\Workspace\build-MyProject-Android_for_armeabi_v7a_GCC_4_9_Qt_5_4_0-Debug\android-build\src\org\qtproject\qt5\android\bindings\, and just copy it.

Then you find those lines in it:

        // now load the application library so it's accessible from this class loader
        if (libName != null)

And load before them, so they become:

        // This is needed for OpenCV!!!

        // now load the application library so it's accessible from this class loader
        if (libName != null)

Note that you pass opencv_java to System.loadLibrary(), even though the file is

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download