Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Added scripts for creating an AAR package and a local Maven repository with OpenCV library#24456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
asmorkalov commentedOct 26, 2023
|
asmorkalov commentedOct 26, 2023
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The script might be executed outside of OpenCV. Please use full path.
alexlyulkovOct 26, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe use __file__ constant?
Uh oh!
There was an error while loading.Please reload this page.
| subprocess.run(["gradlew", "assembleRelease"], | ||
| shell=True, | ||
| cwd=ANDROID_PROJECT_DIR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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 fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I probably fixed the problem, please try again
asmorkalov commentedOct 30, 2023
|
| @@ -0,0 +1,5 @@ | |||
| cmake_minimum_required(VERSION 3.22.1) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Need to reduce required version as low as possible for old NDKs support.
| namespace 'org.opencv' | ||
| compileSdk 33 | ||
| defaultConfig { | ||
| minSdk 21 | ||
| targetSdk 33 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
To be discussed.
| externalNativeBuild { | ||
| cmake { | ||
| path file('src/main/cpp/CMakeLists.txt') | ||
| version '3.22.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
To be discussed.
| groupId = 'org.opencv' | ||
| artifactId = '${PACKAGE_NAME}' | ||
| version = '${OPENCV_VERSION}' | ||
| artifact("opencv-release.aar") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Please useOPENCV_VERSION_MAJOR instead of4 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sounds strange. The file name is defined in the project template. Why do you have options here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I propose to add brief comment to the file why it's empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
The same about empty file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
let's set executable flag to gradlew and remove sh from command line.
asmorkalov commentedNov 1, 2023
Common proposals:
|
…stomization using cmd arguments, added previous data removing on initialization, other minor changes
asmorkalov left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
👍
asmorkalov commentedNov 3, 2023
@mshabunin@opencv-alalek please review too. |
| @@ -0,0 +1,156 @@ | |||
| #!/usr/bin/env python | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| #!/usr/bin/envpython | |
| #!/usr/bin/envpython3 |
I'd suggest usingpathlib 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
At first glance this file seem to repeatbuild_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.#24473Updated 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 locationAdded 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 definitionRequires:-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 libraryopencv#24456Added 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#24473Updated 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 locationAdded 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 hereopencv#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 definitionRequires:-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 libraryopencv#24456Added 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#24473Updated 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 locationAdded 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 hereopencv#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 definitionRequires:-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 libraryopencv#24456Added 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#24473Updated 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 locationAdded 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 hereopencv#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 definitionRequires:-opencv/ci-gha-workflow#124-opencv-infrastructure/opencv-gha-dockerfile#26
Uh oh!
There was an error while loading.Please reload this page.
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.