OpenCV 5.x SDK plus opencv_contrib for Android. You can simply get the repo and add to your Droid project.
Or you can compile by yourself with your specific versions on your Mac. Some helpful links:
- https://github.com/opencv/opencv/releases
- https://github.com/opencv/opencv/wiki/Custom-OpenCV-Android-SDK-and-AAR-package-build
- git pull. Make sure the branch is 5.x. Do the same for opencv_contrib as well. They should be under the same parent folder.
- Go to the opencv folder. Create a folder called build.
- Delete everything under opencv/build every time you run the python command below.
- Important: Find the right NDK version (/Users/xxx/Library/Android/sdk/ndk/28.2.13676358) based on Android Gradle Plugin (AGP) version. For AGP 9.2.1, NDK = 28.2.
If they don't match, then OpenCVLoader.initLocal() in your Android app will fail even though you can still generate the library.
- Make changes as follows (or pick your own version numbers):
- Run the code below in Terminal (at opencv). xxx should be your own username. Again, make sure you change the "28.2.13676358" part for your specific needs.
python3 platforms/android/build_sdk.py \
build \
--ndk_path=/Users/xxx/Library/Android/sdk/ndk/28.2.13676358 \
--sdk_path=/Users/xxx/Library/Android/sdk \
--extra_modules_path=../opencv_contrib/modules \
--config=platforms/android/ndk-25.config.py \
--use_android_buildtools \
--no_samples_build
↑ Takes time. Just be patient...
Notice the last line: the sample project is not part of this build. Delete the line if you want.