As per OpenCV docs(1), below steps using OpenCV manager is the recommended way to use OpenCV for production runs. But, OpenCV manager(2) is an additional install from Google play store. So, if you prefer a self contained apk(not using OpenCV manager) or is currently in development/testing phase, I suggest answer at https://stackoverflow.com/a/27421494/1180117.

Recommended steps for using OpenCV in Android Studio with OpenCV manager.

Unzip OpenCV Android sdk downloaded from OpenCV.org(3) From File -> Import Module , choose sdk/java folder in the unzipped opencv archive. Update build.gradle under imported OpenCV module to update 4 fields to match your project's build.gradle a) compileSdkVersion b) buildToolsVersion c) minSdkVersion and 4) targetSdkVersion. Add module dependency by Application -> Module Settings , and select the Dependencies tab. Click + icon at bottom(or right), choose Module Dependency and select the imported OpenCV module.

As the final step, in your Activity class, add snippet below.

public class SampleJava extends Activity { private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { @Override public void onManagerConnected(int status) { switch(status) { case LoaderCallbackInterface.SUCCESS: Log.i(TAG,"OpenCV Manager Connected"); //from now onwards, you can use OpenCV API Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0)); break; case LoaderCallbackInterface.INIT_FAILED: Log.i(TAG,"Init Failed"); break; case LoaderCallbackInterface.INSTALL_CANCELED: Log.i(TAG,"Install Cancelled"); break; case LoaderCallbackInterface.INCOMPATIBLE_MANAGER_VERSION: Log.i(TAG,"Incompatible Version"); break; case LoaderCallbackInterface.MARKET_ERROR: Log.i(TAG,"Market Error"); break; default: Log.i(TAG,"OpenCV Manager Install"); super.onManagerConnected(status); break; } } }; @Override protected void onResume() { super.onResume(); //initialize OpenCV manager OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback); } }

Note: You could only make OpenCV calls after you receive success callback on onManagerConnected method. During run, you will be prompted for installation of OpenCV manager from play store, if it is not already installed. During development, if you don't have access to play store or is on emualtor, use appropriate OpenCV manager apk present in apk folder under downloaded OpenCV sdk archive .

Pros

Apk size reduction by around 40 MB ( consider upgrades too ).

OpenCV manager installs optimized binaries for your hardware which could help speed.

Upgrades to OpenCV manager might save your app from bugs in OpenCV.

Different apps could share same OpenCV library.

Cons