In order to build the aar library file, firstly we need to build opencv files:
Jan 06, 2016 On www.opencv.org there is a link to download the library for Android. Download it, unpack it. If you've followed the post about compiling OpenCV yourself, you already have a directory in your homedirectory somewhere: opencv/ opencv/opencv-3.1/ opencv/build/ now, add the unpacked Android. Open Computer Vision Library. About; Releases; Courses; Resources. Books; Links; Platforms; Releases. OpenCV – 4.1.2.
Preparation
Update submodule project: opencv and opencv_contrib
Install Android Studio and install necessary components of Android from Android Studio
Download Android NDK r10e from: https://developer.android.com/ndk/downloads/older_releases.html
- Linux: https://dl.google.com/android/repository/android-ndk-r10e-linux-x86_64.zip
- Mac: https://dl.google.com/android/repository/android-ndk-r10e-darwin-x86_64.zip
- P.S. Current opencv (3.4.0) only support up to ndk r10.
Download Android sdk tools version 25.2.5, overwrite
tools
folder inside android sdk folder.- Linux: https://dl.google.com/android/repository/tools_r25.2.5-linux.zip
- Mac: https://dl.google.com/android/repository/tools_r25.2.5-macosx.zip
- P.S. After version 25.5.2,
android
command is deleted which is used by opencv build script.
Install cmake, ninja, ant
- Ubuntu: sudo apt install cmake ninja-build ant
- Mac: brew install cmake ninja ant
Build
Assume directories are as follows:
- ndk: ~/android-ndk-r10e
- sdk: ~/Android/Sdk
- Default sdk directory:
- Linux: ~/Android/Sdk
- Mac: ~/Library/Android/sdk
- Default sdk directory:
Enter dir: fingerprint-frontend/opencv-library
If got error
CMake was unable to find a build program corresponding to 'Ninja'
on Mac, we need to modify ./opencv/platforms/android/build_sdk.py:
- run the build script:
Reference
OpenCV4Android, packaged as a .aar for direct use without depending on the stupid OpenCV Manager app.
Building an .aar of OpenCV-3.x.y for yourself
Building OpenCV-3.x.y for Android is actually quite simple, its just not obvious where to get the pieces and the OpenCV docs hard-sell the 'OpenCV Manager' in favour of the better and easier direct integration approach.
Here's the steps I used to create my .aar:
- Download and extract the OpenCV4Android bundle
- Create a Library Project in Android Studio
- Copy the java source files from OpenCV4Android into src/main/java
- Drop the OpenCV native libraries into src/main/jniLibs
- Run the gradle build
- Et voila, .aar file
Using your glorious new .aar
Reference the maven repository you've deployed your .aar to, e.g. mine (which I can't stop you from using ;)) is:
Include the .aar in your build.gradle file:
Bootstrap OpenCV in your Java code:
Opencv 2.4 Download
Optional but recommended: to keep the downloaded APK size to a minimum, build separate APK's per architecture (approx 10MB each vs 42MB for universal) by placing the following inside the 'android' gradle directive of your application's build.gradle:
Opencv Library For Android Download Windows 7
Disclaimer: This project is simply my bundling of OpenCV as an Android Library. I am not otherwise involved in the OpenCV project, and all credit for the wonderful OpenCV library goes to the developers thereof.