- Use a Linux OS. It is assumed that
Arch Linux
is used. - Install the latest version of
Android Studio
. - Use
SDK Manger
ofAndroid Studio
to install yourSDK 25
,NDK 21.4.7075529
, andBuildTools 25.0.3
of your choice. - Install the packages that we are going to need on your linux:
sudo pacman -S cmake git aria2 ant unzip ant
- Make sure you have a suitable
python2
,python3
, andjdk
If you need the cv1
interface of OpenCV, you should use version < 4. Versions>=4 only have the cv2
interface.
We are going to use OpenCV 3.4.16 .
The android
executable of Android SDK located at sdk/tools/android
which is used by OpenCV's CMake scripts to setup the java module project is depricated by Google. Unfortunately, OpenCV, even the latest versions of it, still use this depricated executable. The workaround is to download an older version of this file from Google and use it instead.
(as described here)
$ cd ~/Downloads
$ aria2 -x8 http://dl-ssl.google.com/android/repository/tools_r25.2.5-linux.zip
$ mv ~/Android/Sdk/tools ~/Android/Sdk/tools.ORIG
$ unzip tools_r25.2.5-linux.zip -d ~/Android/Sdk/
$ cd ~
$ mkdir opencv_repo
$ cd opencv_repo
$ aria2 -x8 https://github.com/opencv/opencv/archive/refs/tags/3.4.16.zip
$ aria2 -x8 https://github.com/opencv/opencv_contrib/archive/refs/tags/3.4.16.zip
$ unzip opencv-3.4.16.zip
$ unzip opencv_contrib-3.4.16.zip
$ cd opencv-3.4.16
$ aria2 https://gist.githubusercontent.com/salehjg/2ce2ef90071eaa3ba7f3404f4094ae12/raw/41f1533729283affb1c02c00af4fd81e9d57aa2b/cmake_conf.sh
Now open cmake_conf.sh
and edit the path lines. Save it and continue.
$ mkdir 00_build
$ mkdir 01_ndk_outputs
$ cd 00_build
$ bash ../cmake_conf.sh
$ make all -j8
$ make install
The NDK version of OpenCV should be available in 01_ndk_outputs
now.
Now that we are finished with the old android
executable, we have to restore the original version of the sdk/tools
directory.
$ rm -rf ~/Android/Sdk/tools
$ mv ~/Android/Sdk/tools.ORIG ~/Android/Sdk/tools