mirror of
https://github.com/opencv/opencv.git
synced 2024-12-12 07:09:12 +08:00
30549d65c2
Added scripts for creating an AAR package and a local Maven repository with OpenCV library #24456 Added scripts for creating an AAR package and a local Maven repository with OpenCV library. The build_java_shared_aar.py script creates AAR with Java + C++ shared libraries. The build_static_aar.py script creates AAR with static C++ libraries. The scripts use an Android project template. The project is almost a default Android AAR library project with empty Java code and one empty C++ library. Only build.gradle.template and CMakeLists.txt.template files contain significant changes. See README.md for more information.
1.5 KiB
1.5 KiB
Scripts for creating an AAR package and a local Maven repository with OpenCV libraries for Android
How to run the scripts
- Set JAVA_HOME and ANDROID_HOME enviroment variables. For example:
export JAVA_HOME=~/Android Studio/jbr
export ANDROID_HOME=~/Android/SDK
- Download OpenCV SDK for Android
- Run build script for version with Java and a shared C++ library:
python build_java_shared_aar.py "~/opencv-4.7.0-android-sdk/OpenCV-android-sdk"
- Run build script for version with static C++ libraries:
python build_static_aar.py "~/opencv-4.7.0-android-sdk/OpenCV-android-sdk"
The AAR libraries and the local Maven repository will be created in the outputs directory
Technical details
The scripts consist of 5 steps:
- Preparing Android AAR library project template
- Adding Java code to the project. Adding C++ public headers for shared version to the project.
- Compiling the project to build an AAR package
- Adding C++ binary libraries to the AAR package. Adding C++ public headers for static version to the AAR package.
- Creating Maven repository with the AAR package
There are a few minor limitations:
- Due to the AAR design the Java + shared C++ AAR package contains duplicates of C++ binary libraries, but the final user's Android application contains only one library instance.
- The compile definitions from cmake configs are skipped, but it shouldn't affect the library because the script uses precompiled C++ binaries from SDK.