OpenCV + Qt + Android, Adding Required Libraries and Includes

Posted on Posted in Android Tutorials, OpenCV Tutorials, Qt Tutorials, Tutorials

Another note to myself which I hope will be useful for others searching it.

Add the following lines to your PRO file in Qt, or create a PRI file using the following and include that in your PRO file.

Note that it is assumed here that OpenCV for Android is extracted to “C:/opencv/OpenCV-android-sdk”

INCLUDEPATH += C:/opencv/OpenCV-android-sdk/sdk/native/jni/include

OPENCV3RDPARTYLIBS = C:/opencv/OpenCV-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a
OPENCVNATIVELIBS = C:/opencv/OpenCV-android-sdk/sdk/native/libs/armeabi-v7a


LIBS += $$OPENCVNATIVELIBS/libopencv_core.a

Note that you need to copy “” to “android-sourceslibsarmeabi-v7a” under your project folder. (If you forget this you’ll face an error mentioning the missing Library file!)

Obviously you should also have the following line in your PRO file so that Qt looks for your Android override files and resources here:


Here OpenCV 2 and Qt 5.4 are used but it should be pretty much the same for other versions. (Later versions perhaps)


(Updated on 2015-12-15)

Or you can just simply download my .PRI file below and include it in your project (if you have OpenCV installed in C drive’s root)


21 thoughts on “OpenCV + Qt + Android, Adding Required Libraries and Includes

  1. thank you for your great post.
    Anyway I have a problem, I followed your post and tried to open an image using cv::imread(…) but couldn’t achieve any succeed. qt showed the error “the vtable symbol may be undefined because the class is missing its key function”. Can you help me with this?

    1. Can you give me a little bit of detail about the configuration you are using? Qt version, OpenCV version etc. Are you using Windows, Linux or Mac?

      1. Thanks for your reply,
        I’m using OpenCV Android 3.0.0, Qt5.5 on Windows 7.
        When I specified the INCLUDEPATH and LIBS in the .pro file, the program builds fine.
        Then I added this line: Mat *mat = new Mat(); it still worked.
        But if I add mat = cv::imread(“C:/file/somefile.jpg”, CV_LOAD_IMAGE_COLOR); the error came in.

      2. I followed your new post and the program still showed that error.
        However if I download and use the older version, OpenCV Android v2.4.11, the one right before v3.0.0, the program runs perfectly. I don’t know why, but it does.
        Anyway thanks for spending time helping me.

        1. As I told you before, seems there are still some imperfections with the OpenCV 3.0.0 build for Android. With some settings it might work for you but I do not recommend using version 3.0.0 for Android as it is unstable currently.

      3. Ok. I have another problem, I can’t get VideoCapture open any video, whether it is a local file on my device, a http url, rtsp url… etc.
        this line works on desktop, but it never runs on my android phone:
        VideoCapture cap(“rtsp://”);

        cap.isOpened() always return false
        Can you help me?

        1. Have you tried opening a local file of a format that is known to work fine with Android? Like MP4 or AVI for example?
          Also please send me the path of local file you are trying to open, in Android exact location of files are confusing sometimes, and it really depends on the permissions you give to your app.

      4. yes I have tried. the video i used is an mp4 file which I downloaded from here
        here is the path:
        I take a screenshot of my video’s details if you want to see:
        I also think that there may be the permission problem, so I gave my program theses 2 permissions:
        my android is 4.4.2

    2. Thanks for your reply,
      I’m using OpenCV Android 3.0.0, Qt5.5 on Windows 7.
      When I specified the INCLUDEPATH and LIBS in the .pro file, the program builds fine.
      Then I added this line: Mat *mat = new Mat(); it still worked.
      But if I add mat = cv::imread(“C:/file/somefile.jpg”, CV_LOAD_IMAGE_COLOR); the error came in.

      1. First of all, I highly recommend using OpenCV 2.4.X (use the highest version) cause it’s much more stable, but generally if you have entered everything correctly then there should not be a problem. (I am also using 2.4.X by the way.)
        On the other hand it is obvious that you have a problem with adding the correct libs. I just made a new post and I suggest you to take a look at it first and compare your code with what I have there. Let me know if it solves your problem. You can find the link below:

  2. Hi,

    My Android Application apk gets created successfully, but when i run it crashes (i installed OpenCV Manager too…)

    I used
    i)Qt 5.5.0 ii)OpenCV-2.4.10-android-sdk iii)Moto G(2nd Gen – Lollipop)

    iv) and copied also..

    Could you please help me.

    1. What you are saying simply means that you are facing a run-time error (and not a compile-time error) My first suggestion would be to try out the latest OpenCV Android SDK to make sure it’s not a bug with OpenCV libraries. I believe the latest version compatible with the libraries you have used is 2.4.12?! (By the way you don’t need to install OpenCV manager at all)

  3. First of all , thanks you for great tutorial . The application gets created successfully.
    I have a problem with my android application apk . when i run it, it crashes for unkown reason ? This is the same problem with @Raja application.
    Could you help me please, it’s took many days now ?
    i have already try all the version of opencv.
    1 – my host : debian
    2- target android 5.1
    3 – Opencv 2.4.10

    1. Hi Diallo
      Can you give me a hint at least as to what your application does? Which main functions do you use? (Camera Galley etc.) And most importantly when does it crash? The main reasons for an application building successfully but crashing at runtime are memory access faults and/or missing runtime libraries. One more question, do you use Qt for building Android apps or are you using Java?

      1. i solve the problem with the crash but know i face to another problem. I have a black screen.
        I’m using qt to build my application. it crash when i launch it.

        1. I didn’t quite get it. Does it crash or not? You said you solved the crash but it’s still crashing?!?!
          Are you able to build Android applications with Qt and without OpenCV? Check if there’s a problem with your Qt for Android configuration.

          1. Sorry for my bad english, i have no problem with Qt and android .

            the problem is when i add opencv library, it open the application on my device with a black screen( No activity).
            i just want to get frames from camera.

          2. It’s OK. I was just trying to understand the issue.
            I really advice against using Camera lib from OpenCV. I never do it myself. It definitely causes problems in all Android devices and it is not reliable at all, at least for now. Even if it works with one version, there is no guarantee that it will continue to run on it after it is updated. But if you insist on using Camera from OpenCV for Android, then you have to make sure you add Camera*.so files. They do not exist on OpenCV 3.X I assume because they gave up on it but you can try for yourself.

            I would also recommend taking a look at this article. With a little bit of modification you can use it with Camera.

          3. Thanks for you kind comments. But please note that this approach may need some modifications in the latest Android update. Let me know if you face any issues.

Leave a Reply

Your email address will not be published. Required fields are marked *