Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
asmorkalov merged 13 commits intoopencv:4.xfromalexlyulkov:al/aar
Nov 7, 2023

Conversation

@alexlyulkov
Copy link
Contributor

@alexlyulkovalexlyulkov commentedOct 26, 2023
edited
Loading

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.

@asmorkalov
Copy link
Contributor

 platforms/android/aar-creating/build_static_aar.py:119: trailing whitespace.+        platforms/android/aar-creating/build_static_aar.py:198: trailing whitespace.+    Error: Process completed with exit code 2.
alexlyulkov reacted with thumbs up emoji

@asmorkalov
Copy link
Contributor

I propose to renameaar-creating ->aar-template

alexlyulkov reacted with thumbs up emoji

["sdk/native/libs/<ABI>/libopencv_java4.so", "prefab/modules/opencv_java4/libs/android.<ABI>/libopencv_java4.so"],
]

ANDROID_PROJECT_TEMPLATE_DIR = "OpenCVAndroidProject"
Copy link
Contributor

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.

Copy link
ContributorAuthor

@alexlyulkovalexlyulkovOct 26, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe use __file__ constant?

Comment on lines 52 to 54
subprocess.run(["gradlew", "assembleRelease"],
shell=True,
cwd=ANDROID_PROJECT_DIR)
Copy link
Contributor

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 file

Copy link
ContributorAuthor

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

@asmorkalovasmorkalov added this to the4.9.0 milestoneOct 26, 2023
@asmorkalov
Copy link
Contributor

python3 /home/alexander/Projects/OpenCV/opencv-master/platforms/android/aar-template/build_java_shared_aar.py /home/alexander/Projects/OpenCV/OpenCV4Android-4.8.1/Preparing Android project...Running gradle assembleRelease...Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details> Configure project :OpenCVChecking the license for package NDK (Side by side) 25.1.8937393 in /home/alexander/Android2/licensesLicense for package NDK (Side by side) 25.1.8937393 accepted.Preparing "Install NDK (Side by side) 25.1.8937393 (revision: 25.1.8937393)"."Install NDK (Side by side) 25.1.8937393 (revision: 25.1.8937393)" ready.Installing NDK (Side by side) 25.1.8937393 in /home/alexander/Android2/ndk/25.1.8937393"Install NDK (Side by side) 25.1.8937393 (revision: 25.1.8937393)" complete."Install NDK (Side by side) 25.1.8937393 (revision: 25.1.8937393)" finished.Checking the license for package Android SDK Build-Tools 30.0.3 in /home/alexander/Android2/licensesLicense for package Android SDK Build-Tools 30.0.3 accepted.Preparing "Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)"."Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" ready.Installing Android SDK Build-Tools 30.0.3 in /home/alexander/Android2/build-tools/30.0.3"Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" complete."Install Android SDK Build-Tools 30.0.3 (revision: 30.0.3)" finished.Checking the license for package Android SDK Platform 33 in /home/alexander/Android2/licensesLicense for package Android SDK Platform 33 accepted.Preparing "Install Android SDK Platform 33 (revision: 3)"."Install Android SDK Platform 33 (revision: 3)" ready.Installing Android SDK Platform 33 in /home/alexander/Android2/platforms/android-33"Install Android SDK Platform 33 (revision: 3)" complete."Install Android SDK Platform 33 (revision: 3)" finished.> Task :OpenCV:compileReleaseJavaWithJavacNote: Some input files use or override a deprecated API.Note: Recompile with -Xlint:deprecation for details.BUILD SUCCESSFUL in 2m 45s39 actionable tasks: 39 executedAdding libs to AAR...Creating local maven repo...Traceback (most recent call last):  File "/usr/lib/python3.6/shutil.py", line 550, in move    os.rename(src, real_dst)FileNotFoundError: [Errno 2] No such file or directory: 'build_java_shared/AndroidProject/OpenCV/build/repo/org/opencv/opencv' -> 'outputs/maven_repo/org/opencv/opencv'During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/home/alexander/Projects/OpenCV/opencv-master/platforms/android/aar-template/build_java_shared_aar.py", line 120, in <module>    main(args.opencv_sdk_path, get_opencv_version(args.opencv_sdk_path))  File "/home/alexander/Projects/OpenCV/opencv-master/platforms/android/aar-template/build_java_shared_aar.py", line 112, in main    path.join(FINAL_REPO_PATH, "org/opencv/opencv"))  File "/usr/lib/python3.6/shutil.py", line 564, in move    copy_function(src, real_dst)  File "/usr/lib/python3.6/shutil.py", line 263, in copy2    copyfile(src, dst, follow_symlinks=follow_symlinks)  File "/usr/lib/python3.6/shutil.py", line 120, in copyfile    with open(src, 'rb') as fsrc:FileNotFoundError: [Errno 2] No such file or directory: 'build_java_shared/AndroidProject/OpenCV/build/repo/org/opencv/opencv'

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.22.1)
Copy link
Contributor

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.

Comment on lines 7 to 12
namespace 'org.opencv'
compileSdk 33

defaultConfig {
minSdk 21
targetSdk 33
Copy link
Contributor

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'
Copy link
Contributor

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")
Copy link
Contributor

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.

Comment on lines 19 to 20
["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"],
Copy link
Contributor

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.

Comment on lines 25 to 26
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
Copy link
Contributor

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?

Copy link
ContributorAuthor

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
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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"
Copy link
Contributor

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"],
Copy link
Contributor

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
Copy link
Contributor

Common proposals:

  • Extract minSdkversion, buildSDK version, CMake version, etc from template and make them command line variables. It allows to build custom aars for newer Android and has different CI configs in different branches.
  • Move both python scripts from aar-template to justplatforms/android and make them executable.

Copy link
Contributor

@asmorkalovasmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

👍

@asmorkalov
Copy link
Contributor

@mshabunin@opencv-alalek please review too.

@asmorkalovasmorkalov merged commit30549d6 intoopencv:4.xNov 7, 2023
@@ -0,0 +1,156 @@
#!/usr/bin/env python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
#!/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
Copy link
Contributor

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?

asmorkalov pushed a commit that referenced this pull requestNov 17, 2023
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
IskXCr pushed a commit to Haosonn/opencv that referenced this pull requestDec 20, 2023
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.
IskXCr pushed a commit to Haosonn/opencv that referenced this pull requestDec 20, 2023
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
@opencv-alalekopencv-alalek removed their request for reviewDecember 26, 2023 20:45
thewoz pushed a commit to thewoz/opencv that referenced this pull requestJan 4, 2024
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.
thewoz pushed a commit to thewoz/opencv that referenced this pull requestJan 4, 2024
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
@asmorkalovasmorkalov mentioned this pull requestJan 19, 2024
thewoz pushed a commit to thewoz/opencv that referenced this pull requestMay 29, 2024
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.
thewoz pushed a commit to thewoz/opencv that referenced this pull requestMay 29, 2024
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
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@mshabuninmshabuninmshabunin left review comments

@asmorkalovasmorkalovasmorkalov approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.9.0

Development

Successfully merging this pull request may close these issues.

3 participants

@alexlyulkov@asmorkalov@mshabunin

[8]ページ先頭

©2009-2025 Movatter.jp