There are three ways to develop with OpenCV on Android. OpenCV Team provides Android Archive (AAR) package distributed with Maven Central, pre-built OpenCV For Android SDK and finally tools and instructions to build OpenCV by yourself. The options are discussed bellow and sorted from easiest to hardest.
Use Maven Central Package
If you are beginner or do not plan to use Contrib modules the official Android archive (AAR) package distributed with Maven Central is your choise. Android Studio and Gradle support this distribution channel out-of-box and the only step you need is to mention OpenCV package as dependency. The option is available since OpenCV 4.9.0 release and will be maintained by the OpenCV Team. We highly recommend this way, if you do not require advanced build options. All usage steps are described in the tutorial “Android Development with OpenCV”. The option is also applicable for all Android samples and available in sample’s build.gradle.
Use the OpenCV4Android SDK distribution
The second option is the default distribution package, which is built for every public OpenCV release and is published on the Github releases page and Sourceforge. The SDK provides the same binaries and Java files as the AAR package, but gives more flexibility. It allows the use of advanced CMake options, ndk-build or link OpenCV statically. Also the SDK may be vendored to your development environment to work offline or in restricted scenarios. . All usage steps are described in the tutorial “Android Development with OpenCV”.
Build OpenCV4Android from sources
This is a hacker level. Actually it is not a special option we propose, but we are open-source (Apache 2.0 license), so you can take the advantage of it! We don’t recommend this way, but if you want to work with the OpenCV sources, you’re welcome! You’re probably want to implement some new features, optimize the performance, submit a pull request. May be you simply want to have access to the latest OpenCV features and keep your finger on the pulse of development.
Pros
- Access to the latest features
- The full freedom of OpenCV hacking
Cons
- You should know the full stack of OpenCV dev tools
- You’ll be an OpenCV beta-tester
We have prepared this tutorial for you: Custom OpenCV Android SDK and AAR package build