-
-
Notifications
You must be signed in to change notification settings - Fork 56.3k
AGP 8.0 build.gradle namespace and aidl buildFeature requirement added #23447
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
OpenCV still uses very old versions of NDK, SDK and Gradle for pre-commit testing and releases. Gradle update at least to 7.3.3 and Android plugin update at least to 7.2 is required. Thanks a lot for the contribution! We will return back to your patch after build infra update. |
Using AGP 7.x basically fix the problem. With AGP 8.0 it become mandatory, it does fix that too |
endforeach() | ||
|
||
# set build.gradle namespace | ||
set(OPENCV_NAMESPACE "org.opencv" CACHE STRING "OpenCV Namespace string") |
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 use version check to avoid breaking of existed build configurations:
if(... GRADLE VERSION CHECK ...)
ocv_update(OPENCV_NAMESPACE_DECLARATION "namespace 'org.opencv'")
else()
ocv_update(OPENCV_NAMESPACE_DECLARATION "")
endif()
and below:
android {
+ @OPENCV_NAMESPACE_DECLARATION@
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 made those changes accordingly so please check it out.
346eaa2
to
c0df098
Compare
I don't wanna open up a new pull request and I can If needs to be but we also need to add
https://developer.android.com/build/releases/gradle-plugin#default-changes Inside of the gradle file because new default become false, gradle 7 and 5 was "true" so it won't effect them and It should be fine for people who start brand new project so they can avoid aidl error for people who start with new gradle 8.0 |
@asmorkalov I was also looking for JDK version but could not found it. https://developer.android.com/build/releases/gradle-plugin#compatibility-8-0-0 also set JDK minimum to 17. As far as I know opencv uses jdk 11 but user needs to set them to 17 for newer gradle 8.0+ for old versions they can leave as it is. I already tested JDK 17 and it works fine. For gradle 8.0
For older version I just need to VERSION_11 (based on opencv minimum) I would like to add this so It can build without error. So can we add at least something similar to gradle or add hard coded VERSION_11 and advise users to change on of top gradle readme like similar to set SDK versions |
CI reports issue:
|
2baf144
to
673667c
Compare
# set build.gradle namespace | ||
if(GRADLE_VERSION STREQUAL "5.6.4") | ||
ocv_update(OPENCV_NAMESPACE_DECLARATION "") | ||
else() | ||
ocv_update(OPENCV_NAMESPACE_DECLARATION "namespace 'org.opencv'") | ||
endif() |
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.
What would happen if GRADLE_VERSION
is 5.6.3?
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.
Namescape came with AGP 7.3 (https://developer.android.com/build/releases/gradle-plugin) so is it okay to set minimum 7.3.0 and any higher should be fine. Any lower version basically won't use it. That include 5.6.3 or any X version lower then 7.3.0
# set build.gradle namespace
if(GRADLE_VERSION VERSION_GREATER_EQUAL "7.3.0")
ocv_update(OPENCV_NAMESPACE_DECLARATION "namespace 'org.opencv'")
else()
ocv_update(OPENCV_NAMESPACE_DECLARATION "")
endif()
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.
Right, condition should use GE version check instead of strong equality.
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.
Did you mean this ?
if(GRADLE_VERSION VERSION_GREATER "7.2.9").
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.
Both cases should do the similar thing:
if(GRADLE_VERSION VERSION_GREATER_EQUAL "7.3.0")
if(GRADLE_VERSION VERSION_GREATER "7.2.9")
The first option is clear however.
BTW, "gradle plugin version" is not the same as "gradle version".
Plugin version is specified through ANDROID_GRADLE_PLUGIN_VERSION
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 changed with AGP and push it.
4cab819
to
44a8822
Compare
Signed-off-by: Onuralp SEZER <[email protected]>
Signed-off-by: Onuralp SEZER <[email protected]>
44a8822
to
19d9b65
Compare
@opencv-alalek can AGP version set to at least 4.1 ? AGP 8.0 gonna is failing in "aidl" and current AGP is too old to understand aidl feature. If it is gonna stay for now, How can I add multi line with "\n" "\t" etc. ? Because I need to add into either same condition or need to set different condition and set to >= 4.1 and as well. Action : https://github.com/opencv/opencv/actions/runs/4738797811/jobs/8421666401#step:12:500 |
@opencv-alalek I also need suggestion for this one too because of AGP(8.0) again. |
Perhaps we need to introduce some variable for Java version (similar to |
add "ANDROID" into namespace variable avoid future name conflict Signed-off-by: Onuralp SEZER <[email protected]>
@opencv-alalek both changed added. |
@onuralpszr Thanks! Triggered CI with latest changes. Please take a look on the comment above about |
Sure, based on suggestion here is how is it look like Cmake file changes set(ANDROID_GRADLE_JAVA_VERSION 1.8 CACHE STRING "Android Gradle Java version")
message(STATUS "Android Gradle Java version: ${ANDROID_GRADLE_JAVA_VERSION}") # set android gradle java version in build.gradle
if(NOT (ANDROID_GRADLE_PLUGIN_VERSION VERSION_LESS "8.0.0"))
# AGP-8.0 requires a minimum JDK version of JDK17
ocv_update(ANDROID_GRADLE_JAVA_VERSION "17")
else()
ocv_update(ANDROID_GRADLE_JAVA_VERSION "${ANDROID_GRADLE_JAVA_VERSION}")
endif() Build.gradle file changes compileOptions {
sourceCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION@
targetCompatibility JavaVersion.VERSION_@ANDROID_GRADLE_JAVA_VERSION@
} |
Looks good. |
I added JDK sections please trigger CI and one more thing, I removed "aidl" part temporally because it needs to be added via condition because current AGP in CI not support "buildFeatures" which failed on last CI trigger. buildFeatures {
aidl true
} |
0b5deb7
to
38c184f
Compare
I set to JDK 1.8 based on CI and I also fix the typo "AGP8.0 JDK version 17 not 18 sorry about that. I fix both and please trigger the CI |
38c184f
to
4fed337
Compare
BTW, there are "config" files for Android packages here: https://github.com/opencv/opencv/tree/4.x/platforms/android It makes sense to create new one configuration file which describes your tested configuration (where to pass required CMake parameters (like |
set(ANDROID_GRADLE_PLUGIN_VERSION "3.2.1" CACHE STRING "Android Gradle Plugin version") | ||
message(STATUS "Android Gradle Plugin version: ${ANDROID_GRADLE_PLUGIN_VERSION}") | ||
|
||
set(ANDROID_GRADLE_JAVA_VERSION "1_8" CACHE STRING "Android Gradle Java version") |
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.
ocv_update(ANDROID_GRADLE_JAVA_VERSION "17")
below would not work after that (there is "no op" logic if value exists for the variable)
We could use it in this form (condition check should go first) - see _INIT
suffix:
# set android gradle java version in build.gradle
if(NOT (ANDROID_GRADLE_PLUGIN_VERSION VERSION_LESS "8.0.0"))
# AGP-8.0 requires a minimum JDK version of JDK17
ocv_update(ANDROID_GRADLE_JAVA_VERSION_INIT "17")
else()
ocv_update(ANDROID_GRADLE_JAVA_VERSION_INIT "1_8")
endif()
set(ANDROID_GRADLE_JAVA_VERSION "${ANDROID_GRADLE_JAVA_VERSION_INIT}" CACHE STRING "Android Gradle Java version")
message(STATUS "Android Gradle Java version: ${ANDROID_GRADLE_JAVA_VERSION}")
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 pushed the changes
and set minimum version to JDK 1_8 for Android builds, use JDK17 for AGP version 8.0 or above. Signed-off-by: Onuralp SEZER <[email protected]>
4fed337
to
889b0b6
Compare
I am not sure I understand this, because problem is based on AGP/Gradle/Java but not "cmake" ? I didn't understand that adding another config file based on "which ndk" version ? |
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.
LGTM 👍
@opencv-alalek we still need to add "aidl" part without that it will fail on version 8.0.0 and above. # set android gradle java version in build.gradle and set aidl config
if(NOT (ANDROID_GRADLE_PLUGIN_VERSION VERSION_LESS "8.0.0"))
# AGP-8.0 requires a minimum JDK version of JDK17
ocv_update(ANDROID_GRADLE_JAVA_VERSION_INIT "17")
# Enable aidl configuration for OpenCV compile with AGP-8.0
ocv_update(ANDROID_GRADLE_BUILD_FEATURE_AIDL "buildFeatures { aidl true }")
else()
ocv_update(ANDROID_GRADLE_JAVA_VERSION_INIT "1_8")
ocv_update(ANDROID_GRADLE_BUILD_FEATURE_AIDL "")
endif() |
Signed-off-by: Onuralp SEZER <[email protected]>
Thank you for reviews. |
The solution haven't quite worked for me. It worked after I modified gradle script as follows:
|
For building SDK or using SDK ? Because for usagei I made a template project for a while ago and I am using standard android project and you can see in this config and patch and you even try yourself it is works. I also made a CI so we can see it does build. https://github.com/onuralpszr/CvCamera-Mobile/blob/main/patches/cv_build_gradle.patch Do you have a project shows you it is not builds ? Another side note they gonna remove both them in version 9.0 https://cs.android.com/android-studio/platform/tools/base/+/0bc1c23297760643b03e8cfd8acc52c007a99cd6 |
When I imported OpenCV and tried to build my project. It failed on missing BuildConfig class. Once I added the |
When I imported OpeCV in my android studio project (Android Studio Giraffe | 2022.3.1 Patch 2) and I tried to build my project appear the next error |
AGP 8.0 build.gradle namespace and aidl buildFeature requirement added opencv#23447 Hello, Android Gradle Plugin version 8.0 is asking for namespace. This is become mandatory and after I update my AGP to 8.0, I got this error ``` Namespace not specified. Please specify a namespace in the module's build.gradle file like so: android { namespace 'com.example.namespace' } If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information. ``` This change fix this future releases. However I am not sure how opencv wants to user namespace I used "org.opencv" if there is a different namespace please let me know so I can changed that too. Also should I add namepsace into "opencv/modules/java/android_sdk/android_gradle_lib/build.gradle" here ? ### Sources Android developer link: https://developer.android.com/studio/preview/features#namespace-dsl Issue Tracker Google: https://issuetracker.google.com/issues/191813691?pli=1#comment19 ### 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
Hi, I added module OpenCV to my android project on kotlin, try to invoke VideoCapture, but after build take issue "could not find "libopencv_java490.so"". I have found "libopencv_java4.so" in my project. Can anyone help me with my problem? |
AGP 8.0 build.gradle namespace and aidl buildFeature requirement added opencv#23447 Hello, Android Gradle Plugin version 8.0 is asking for namespace. This is become mandatory and after I update my AGP to 8.0, I got this error ``` Namespace not specified. Please specify a namespace in the module's build.gradle file like so: android { namespace 'com.example.namespace' } If the package attribute is specified in the source AndroidManifest.xml, it can be migrated automatically to the namespace value in the build.gradle file using the AGP Upgrade Assistant; please refer to https://developer.android.com/studio/build/agp-upgrade-assistant for more information. ``` This change fix this future releases. However I am not sure how opencv wants to user namespace I used "org.opencv" if there is a different namespace please let me know so I can changed that too. Also should I add namepsace into "opencv/modules/java/android_sdk/android_gradle_lib/build.gradle" here ? ### Sources Android developer link: https://developer.android.com/studio/preview/features#namespace-dsl Issue Tracker Google: https://issuetracker.google.com/issues/191813691?pli=1#comment19 ### 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
Hello,
Android Gradle Plugin version 8.0 is asking for namespace. This is become mandatory and after I update my AGP to 8.0, I got this error
This change fix this future releases. However I am not sure how opencv wants to user namespace I used "org.opencv" if there is a different namespace please let me know so I can changed that too. Also should I add namepsace into "opencv/modules/java/android_sdk/android_gradle_lib/build.gradle" here ?
Sources
Android developer link: https://developer.android.com/studio/preview/features#namespace-dsl
Issue Tracker Google: https://issuetracker.google.com/issues/191813691?pli=1#comment19
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.