When developing Computer Vision applications using OpenCV for the Android platform, developers often face difficulties in getting a OpenCV build for their project. The official OpenCV Android builds often fall short as they do not ship with the OpenCV contrib modules. So most developers end up compiling OpenCV to suit their needs in the product development journey. This is when the options available on the compilation process create confusion and result in much of the compilation woes. The article aims to answer some of the compilation choices and provides best practice suggestions for OpenCV compilation for Android. If you are interested only in using the prebuilt 64bit OpenCV binaries for Android, you can skip the contents below and download the binaries from this Dropbox location.
Always use the CMake supplied from the Android NDK for building C / C++ programs for Android. The regular CMake build, outside of the NDK, also has support for Android NDK, but this is often broken when using this CMake to build libraries like OpenCV, OpenSSL etc for Android. Android strongly discourages the use of CMake that is not supplied as a part of its NDK. There is an active open issue on android NDK Github repository on this topic.
The OpenCV project is quite mature and supports a wide range of compilers including GCC and Clang. Traditionally the Android NDK had supported both the GCC and Clang compilers. During the release of the v17 version of the NDK, the changelog of the release mentioned that the GCC will no longer be supported and will be removed from the subsequent NDK releases. The NDK version r18b has removed the support for GCC compiler completely and Clang is the only version that is supported from r18 and above. Please refer to the Announcements section on corresponding NDK releases for further clarifications.
The Android NDK supports the ABI versions arm64-v8a, armeabi-v7a, x86 and x86_64. There has been a greater push to support both 32 bit and 64 bit versions of the apps that are published in the Play Store. Beginning from August 2019, all applications will require support for 64 bit version of their application. When using OpenCV NDK code, it is essential that OpenCV is compiled with support for arm64-v8a. The following build configuration just works out of the box for building OpenCV and has been tested by us. The pre-build binaries for the below configuration is available from this Dropbox location.
|Android SDK tools version||25.2.5|
|Targets supported||arm64-v8a and armeabi-v7a|
The build command used to build the above configuration is as below