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#24456asmorkalov merged 13 commits intoopencv:4.xfrom
Conversation
|
|
I propose to rename |
| ["sdk/native/libs/<ABI>/libopencv_java4.so", "prefab/modules/opencv_java4/libs/android.<ABI>/libopencv_java4.so"], | ||
| ] | ||
|
|
||
| ANDROID_PROJECT_TEMPLATE_DIR = "OpenCVAndroidProject" |
There was a problem hiding this comment.
The script might be executed outside of OpenCV. Please use full path.
There was a problem hiding this comment.
Maybe use __file__ constant?
| subprocess.run(["gradlew", "assembleRelease"], | ||
| shell=True, | ||
| cwd=ANDROID_PROJECT_DIR) |
There was a problem hiding this comment.
Please check build status. I get error on the next steps, if something went wrong:
Adding libs to AAR...
Traceback (most recent call last):
File "./build_java_shared_aar.py", line 92, in <module>
main(args.opencv_sdk_path, args.opencv_version)
File "./build_java_shared_aar.py", line 60, in main
shutil.unpack_archive(COMPILED_AAR_PATH, AAR_UNZIPPED_DIR, "zip")
File "/usr/lib/python3.6/shutil.py", line 974, in unpack_archive
func(filename, extract_dir, **dict(format_info[2]))
File "/usr/lib/python3.6/shutil.py", line 883, in _unpack_zipfile
raise ReadError("%s is not a zip file" % filename)
shutil.ReadError: build_java_shared/AndroidProject/OpenCV/build/outputs/aar/opencv-release.aar is not a zip file
There was a problem hiding this comment.
I probably fixed the problem, please try again
… with 2 package names, minor refactoring
|
| @@ -0,0 +1,5 @@ | |||
| cmake_minimum_required(VERSION 3.22.1) | |||
There was a problem hiding this comment.
Need to reduce required version as low as possible for old NDKs support.
| namespace 'org.opencv' | ||
| compileSdk 33 | ||
|
|
||
| defaultConfig { | ||
| minSdk 21 | ||
| targetSdk 33 |
| externalNativeBuild { | ||
| cmake { | ||
| path file('src/main/cpp/CMakeLists.txt') | ||
| version '3.22.1' |
| groupId = 'org.opencv' | ||
| artifactId = '${PACKAGE_NAME}' | ||
| version = '${OPENCV_VERSION}' | ||
| artifact("opencv-release.aar") |
There was a problem hiding this comment.
I propose to substitute OpenCV version to the file name.
| ["sdk/native/libs/<ABI>/libopencv_java4.so", "jni/<ABI>/libopencv_java4.so"], | ||
| ["sdk/native/libs/<ABI>/libopencv_java4.so", "prefab/modules/opencv_java4/libs/android.<ABI>/libopencv_java4.so"], |
There was a problem hiding this comment.
Please use OPENCV_VERSION_MAJOR instead of 4 to prevent issues with 5.x.
| COMPILED_AAR_PATH_1 = path.join(ANDROID_PROJECT_DIR, "OpenCV/build/outputs/aar/OpenCV-release.aar") # original package name | ||
| COMPILED_AAR_PATH_2 = path.join(ANDROID_PROJECT_DIR, "OpenCV/build/outputs/aar/opencv-release.aar") # lower case package name |
There was a problem hiding this comment.
Sounds strange. The file name is defined in the project template. Why do you have options here?
There was a problem hiding this comment.
For some reason I have different filenames on Windows and Linux. Probably because of different Android SDK versions.
| ["sdk/java/res", "OpenCV/src/main/res"] | ||
| ] | ||
|
|
||
| ABIS = ["arm64-v8a", "armeabi-v7a", "x86", "x86_64"] # if you want to change it, you also need to change Android project template |
There was a problem hiding this comment.
I propose to build the list of ABIs from SDK content by listing sdk/native/libs. User may build custom SDK for reduced list of architectures. Also I do not see platforms definition in the Android project template.
There was a problem hiding this comment.
I propose to add brief comment to the file why it's empty.
There was a problem hiding this comment.
The same about empty file.
There was a problem hiding this comment.
It's not required. It's not recommend to build OpenCV inside source tree.
| COMPILED_AAR_PATH_1 = path.join(ANDROID_PROJECT_DIR, "OpenCV/build/outputs/aar/OpenCV-release.aar") # original package name | ||
| COMPILED_AAR_PATH_2 = path.join(ANDROID_PROJECT_DIR, "OpenCV/build/outputs/aar/opencv-release.aar") # lower case package name | ||
| AAR_UNZIPPED_DIR = "build_java_shared/aar_unzipped" | ||
| FINAL_AAR_PATH = "outputs/opencv_java_shared.aar" |
There was a problem hiding this comment.
Add version to the file name.
| print("Creating local maven repo...") | ||
|
|
||
| shutil.copy(FINAL_AAR_PATH, path.join(ANDROID_PROJECT_DIR, "OpenCV/opencv-release.aar")) | ||
| subprocess.run(["sh", "gradlew", "publishReleasePublicationToMyrepoRepository"], |
There was a problem hiding this comment.
let's set executable flag to gradlew and remove sh from command line.
|
Common proposals:
|
…stomization using cmd arguments, added previous data removing on initialization, other minor changes
|
@mshabunin @opencv-alalek please review too. |
| @@ -0,0 +1,156 @@ | |||
| #!/usr/bin/env python | |||
There was a problem hiding this comment.
| #!/usr/bin/env python | |
| #!/usr/bin/env python3 |
I'd suggest using pathlib for all path/file related operations (https://docs.python.org/3.8/library/pathlib.html#correspondence-to-tools-in-the-os-module).
We support python 3.8+, do we?
| @@ -0,0 +1,229 @@ | |||
| #!/usr/bin/env python | |||
There was a problem hiding this comment.
At first glance this file seem to repeat build_java_shared_aar.py in many aspects, is it possible to join these files into a single script with --static/--dynamic flag?
Updated Android samples for modern Android studio. Added OpenCV from Maven support. #24473 Updated samples for recent Android studio: - added namespace field that is required in build.gradle files - replaced _switch_ by _if-else_ because it doesn't work with constants from resources - added missed log library dependency in face-detection/jni/CMakeLists.txt - use local.properties to define NDK location Added support for OpenCV from Maven. Now you can choose 3 possible sources of OpenCV lib in settings.gradle: SDK path, local Maven repository, public Maven repository. (Creating Maven repository from SDK is added here #24456 ) There are differences in project configs for SDK and Maven versions: - different dependencies in build.gradle - different OpenCV library names in CMakeLists.txt - SDK version requires OpenCV_DIR definition Requires: - opencv/ci-gha-workflow#124 - opencv-infrastructure/opencv-gha-dockerfile#26
Added scripts for creating an AAR package and a local Maven repository with OpenCV library opencv#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.
Updated Android samples for modern Android studio. Added OpenCV from Maven support. opencv#24473 Updated samples for recent Android studio: - added namespace field that is required in build.gradle files - replaced _switch_ by _if-else_ because it doesn't work with constants from resources - added missed log library dependency in face-detection/jni/CMakeLists.txt - use local.properties to define NDK location Added support for OpenCV from Maven. Now you can choose 3 possible sources of OpenCV lib in settings.gradle: SDK path, local Maven repository, public Maven repository. (Creating Maven repository from SDK is added here opencv#24456 ) There are differences in project configs for SDK and Maven versions: - different dependencies in build.gradle - different OpenCV library names in CMakeLists.txt - SDK version requires OpenCV_DIR definition Requires: - opencv/ci-gha-workflow#124 - opencv-infrastructure/opencv-gha-dockerfile#26
Added scripts for creating an AAR package and a local Maven repository with OpenCV library opencv#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.
Updated Android samples for modern Android studio. Added OpenCV from Maven support. opencv#24473 Updated samples for recent Android studio: - added namespace field that is required in build.gradle files - replaced _switch_ by _if-else_ because it doesn't work with constants from resources - added missed log library dependency in face-detection/jni/CMakeLists.txt - use local.properties to define NDK location Added support for OpenCV from Maven. Now you can choose 3 possible sources of OpenCV lib in settings.gradle: SDK path, local Maven repository, public Maven repository. (Creating Maven repository from SDK is added here opencv#24456 ) There are differences in project configs for SDK and Maven versions: - different dependencies in build.gradle - different OpenCV library names in CMakeLists.txt - SDK version requires OpenCV_DIR definition Requires: - opencv/ci-gha-workflow#124 - opencv-infrastructure/opencv-gha-dockerfile#26
Added scripts for creating an AAR package and a local Maven repository with OpenCV library opencv#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.
Updated Android samples for modern Android studio. Added OpenCV from Maven support. opencv#24473 Updated samples for recent Android studio: - added namespace field that is required in build.gradle files - replaced _switch_ by _if-else_ because it doesn't work with constants from resources - added missed log library dependency in face-detection/jni/CMakeLists.txt - use local.properties to define NDK location Added support for OpenCV from Maven. Now you can choose 3 possible sources of OpenCV lib in settings.gradle: SDK path, local Maven repository, public Maven repository. (Creating Maven repository from SDK is added here opencv#24456 ) There are differences in project configs for SDK and Maven versions: - different dependencies in build.gradle - different OpenCV library names in CMakeLists.txt - SDK version requires OpenCV_DIR definition Requires: - opencv/ci-gha-workflow#124 - opencv-infrastructure/opencv-gha-dockerfile#26
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.