opencv/platforms/android/aar-template
Alexander Smorkalov c803aa2ddd
Merge pull request #26057 from asmorkalov:as/android_16k_pages
Android builds update #26057

Fixes https://github.com/opencv/opencv/issues/26027
Should also address https://github.com/opencv/opencv/issues/26542
 
Changes:
- Switched to Android build tools 34, NDK 26d, target API level 34 (required by Google Play).
- Use flexible page size on Android by default to support Android 15+.
- Dummy stub for R and BuildConfig classes for javadoc.
- Java 17 everywhere.
- Strict ndkVersion and ABI list in release package.

Related:
- Docker: https://github.com/opencv-infrastructure/opencv-gha-dockerfile/pull/41
- Pipeline: https://github.com/opencv/ci-gha-workflow/pull/183

Related IPP issue with NDK 27+: https://github.com/opencv/opencv/issues/26072

Google documentation for 16kb pages support : https://developer.android.com/guide/practices/page-sizes?hl=en

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2024-12-31 11:53:04 +03:00
..
gradle/wrapper Merge pull request #26057 from asmorkalov:as/android_16k_pages 2024-12-31 11:53:04 +03:00
OpenCV Merge pull request #26057 from asmorkalov:as/android_16k_pages 2024-12-31 11:53:04 +03:00
build.gradle Merge pull request #26057 from asmorkalov:as/android_16k_pages 2024-12-31 11:53:04 +03:00
gradle.properties Merge pull request #24456 from alexlyulkov:al/aar 2023-11-07 14:23:33 +03:00
gradlew Merge pull request #24456 from alexlyulkov:al/aar 2023-11-07 14:23:33 +03:00
gradlew.bat Merge pull request #24456 from alexlyulkov:al/aar 2023-11-07 14:23:33 +03:00
README.md correct "enviroment" to "environment" 2024-08-11 22:27:36 +08:00
settings.gradle Merge pull request #24456 from alexlyulkov:al/aar 2023-11-07 14:23:33 +03:00

Scripts for creating an AAR package and a local Maven repository with OpenCV libraries for Android

How to run the scripts

  1. Set JAVA_HOME and ANDROID_HOME environment variables. For example:
export JAVA_HOME=~/Android Studio/jbr
export ANDROID_HOME=~/Android/SDK
  1. Download OpenCV SDK for Android
  2. 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"
  1. 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:

  1. Preparing Android AAR library project template
  2. Adding Java code to the project. Adding C++ public headers for shared version to the project.
  3. Compiling the project to build an AAR package
  4. Adding C++ binary libraries to the AAR package. Adding C++ public headers for static version to the AAR package.
  5. Creating Maven repository with the AAR package

There are a few minor limitations:

  1. 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.
  2. The compile definitions from cmake configs are skipped, but it shouldn't affect the library because the script uses precompiled C++ binaries from SDK.