loading...
  1. How to Easily Install OpenCV in Android Studio?

How to Easily Install OpenCV in Android Studio?

Hello Friends,

A small and sweet post in between all those C, C++ and Python OpenCV Tutorials. I have received several emails from folks who were interested in knowing how to easily install/integrate OpenCV with Android Studio.

The below steps for using Android OpenCV sdk in Android Studio.

  1. Download latest OpenCV sdk for Android from OpenCV.org and decompress the zip file.
  2. Import OpenCV to Android Studio, From File -> New -> Import Module, choose sdk/javafolder in the unzipped opencv archive.
  3. Update build.gradle under imported OpenCV module to update 4 fields to match your project build.gradle a) compileSdkVersion b) buildToolsVersion c) minSdkVersion and d) targetSdkVersion.
  4. Add module dependency by Application -> Module Settings, and select the Dependenciestab. Click + icon at bottom, choose Module Dependency and select the imported OpenCV module.
    • For Android Studio v1.2.2, to access to Module Settings : in the project view, right-click the dependent module -> Open Module Settings
  5. Copy libs folder under sdk/native to Android Studio under app/src/main.
  6. In Android Studio, rename the copied libs directory to jniLibs and we are done.

Step (6) is since Android studio expects native libs in app/src/main/jniLibs instead of older libsfolder. For those new to Android OpenCV, don’t miss below steps

  • include static{ System.loadLibrary(“opencv_java”); } (Note: for OpenCV version 3 at this step you should instead load the library opencv_java3.)
  • For step(5), if you ignore any platform libs like x86, make sure your device/emulator is not on that platform.

OpenCV written is in C/C++. Java wrappers are

  1. Android OpenCV SDK – OpenCV.org maintained Android Java wrapper. I suggest this one.
  2. OpenCV Java – OpenCV.org maintained auto generated desktop Java wrapper.
  3. JavaCV – Popular Java wrapper maintained by independent developer(s). Not Android specific. This library might get out of sync with OpenCV newer versions.




Leave a Reply

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

Welcome to OpenCV World !! Come as a Guest, stay as a Family