Skip to content

fixes #5208: Gradle build fails with android studio flamingo update #5220

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

Merged

Conversation

sivasubramaniamv
Copy link
Contributor

@sivasubramaniamv sivasubramaniamv commented May 3, 2023

Fixes #5208

What changes did you make and why?

  1. Upgraded Gradle version from 6.9 to 8.1.1
  2. Upgraded AGP version from 4.0.1 to 8.0.0

Tested betaDebug on

  1. Realme 3 Pro with API level 30 (Android 11)

Individual comments have been added to specific changes. Changes that do not contain individual comments are either self-explanatory or made by the AGP upgrade assistant.

Note: As part of this upgrade a change was required in translatewiki which has been merged.

app/build.gradle Outdated
@@ -168,7 +168,7 @@ project.gradle.taskGraph.whenReady {
}

android {
compileSdkVersion 31
compileSdkVersion 33
Copy link
Contributor Author

@sivasubramaniamv sivasubramaniamv May 3, 2023

Choose a reason for hiding this comment

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

Changed CompileSdkVersion from 31 to 33. Fixes error as described in this stack overflow issue.

app/build.gradle Outdated
implementation ("com.squareup.okhttp3:okhttp:$OKHTTP_VERSION"){
force = true //API 19 support
implementation ("com.squareup.okhttp3:okhttp:$OKHTTP_VERSION!!"){
//force = true //API 19 support
Copy link
Contributor Author

@sivasubramaniamv sivasubramaniamv May 3, 2023

Choose a reason for hiding this comment

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

Forcing dependency versions using force = true on a first-level dependency has been deprecated.

Refer to Gradle documentation.

Also, the minSdkVersion is 29 for this project.

Copy link
Member

Choose a reason for hiding this comment

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

Also, the minSdkVersion is 29 for this project.

We've pushed it back to 21, recently. I hope that doesn't affect this change 🙂

app/build.gradle Outdated
@@ -341,7 +340,11 @@ android {
buildFeatures {
viewBinding true
}

namespace 'fr.free.nrw.commons'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the namespace DSL to the android {} block in the module-level build.gradle file and removed the package attribute in the manifest.

This change was made as part of preparing the app build for the Android Studio Flamingo release.

Refer to this medium article.

@@ -16,7 +16,7 @@ open class OnSwipeTouchListener(context: Context?) : View.OnTouchListener {
private val SWIPE_THRESHOLD_WIDTH = (getScreenResolution(context!!)).first / 3
private val SWIPE_VELOCITY_THRESHOLD = 1000

override fun onTouch(view: View?, motionEvent: MotionEvent?): Boolean {
override fun onTouch(view: View?, motionEvent: MotionEvent): Boolean {
Copy link
Contributor Author

@sivasubramaniamv sivasubramaniamv May 3, 2023

Choose a reason for hiding this comment

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

Changed parameter type from motionEvent: MotionEvent? to MotionEvent.

Fixes error: Type mismatch: inferred type is MotionEvent? but MotionEvent was expected

@@ -32,7 +32,7 @@ open class OnSwipeTouchListener(context: Context?) : View.OnTouchListener {

inner class GestureListener : GestureDetector.SimpleOnGestureListener() {

override fun onDown(e: MotionEvent?): Boolean {
override fun onDown(e: MotionEvent): Boolean {
Copy link
Contributor Author

@sivasubramaniamv sivasubramaniamv May 3, 2023

Choose a reason for hiding this comment

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

Changed parameter type from e: MotionEvent? to MotionEvent.

Fixes error: 'onDown' overrides nothing

build.gradle Outdated
gradlePluginPortal() // potential jcenter() replacement
maven { url "https://jitpack.io" }
maven { url "https://maven.google.com" }
}
Copy link
Contributor Author

@sivasubramaniamv sivasubramaniamv May 3, 2023

Choose a reason for hiding this comment

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

Replaced deprecated jcenter() convenience method with gradlePluginPortal() as JCenter was shutdown.

Gradle Plugin Portal was added as the JCenter dependency CircleProgressBar 1.1.1 was not available on Maven Central.

Refer to this stack overflow issue and this github issue.

@@ -14,7 +14,6 @@
# org.gradle.parallel=true
#Thu Mar 01 15:28:48 IST 2018
org.gradle.jvmargs=-Xmx1536M
android.enableBuildCache=true
Copy link
Contributor Author

@sivasubramaniamv sivasubramaniamv May 3, 2023

Choose a reason for hiding this comment

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

Removed android.enableBuildCache = true

Gradle build cache has superseded Android-specific build caches.

Copy link
Member

Choose a reason for hiding this comment

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

Gradle build cache has superseded Android-specific build caches.

Do we not need to add org.gradle.caching=true in our gradle.properties to enable Gradle build cache ? 🤔

android.jetifier.ignorelist=bcprov-jdk15on
Copy link
Contributor Author

@sivasubramaniamv sivasubramaniamv May 3, 2023

Choose a reason for hiding this comment

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

Changed android.jetifier.blacklist to android.jetifier.ignorelist.

Refer to this GitHub comment for more detail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed code for publishing library that caused a few errors. Library publishing code is unnecessary as the library is discontinued and contained within the main project.

Copy link
Member

@nicolas-raoul nicolas-raoul left a comment

Choose a reason for hiding this comment

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

The app is building and running fine with this PR merged.
I will test a bit more and merge if @sivaraam and @RitikaPahwa4444 are OK.

Copy link
Member

@sivaraam sivaraam left a comment

Choose a reason for hiding this comment

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

Thanks for taking this up and making the app works on newer Android Studio versions!

For the note, the version 8 of Android Gradle plugin seems to bump the JDK requirement to 17. Mentioning it here just for reference. In case anyone is stuck with Java 11 or so, they could bump the Gradle plugin down to 7.3.1. The app seems to build fine with that too. Also that Gradle plugin version enables the building the app on Android Studio Dolphin and also likely on the Electric Eel version.

build.gradle Outdated
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:8.0.0'
Copy link
Member

Choose a reason for hiding this comment

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

Looks like 8.0.2 is already out. Could you kindly bump this up to 8.0.2 ?

@sivaraam
Copy link
Member

sivaraam commented Jun 25, 2023

It also seems like the GitHub workflow would need to be tweaked a bit to start using JDK 17 due to the changes in this MR. Could you kindly adjust that too @siva-subramaniam-v ?

@sivasubramaniamv
Copy link
Contributor Author

@sivaraam I tried making the CI work, but it doesn't seem to be working. I don't have much experience working with CI. Please assign it to someone with prior experience.

@sivaraam
Copy link
Member

sivaraam commented Jul 8, 2023

@sivaraam I tried making the CI work, but it doesn't seem to be working. I don't have much experience working with CI. Please assign it to someone with prior experience.

I've tried putting in a change which should hopefully fix the pipeline. Let's see 🤞🏼

@nicolas-raoul
Copy link
Member

fr.free.nrw.commons.AboutActivityUnitTests > checkActivityNotNull FAILED
    java.lang.NoSuchMethodError at ProxyMaker.java:111

:'-(

@nicolas-raoul
Copy link
Member

nicolas-raoul commented Sep 17, 2023

If you update roboelectric to 4.10.3, the number of failed tests falls from all to only 5. :-)
It is OK to add an @Ignore to these 5 unit tests, and create an issue so that someone can fix them in the future.

@shankarpriyank
Copy link
Contributor

hi @siva-subramaniam-v can you please push this fix, it would help a lot

If you update roboelectric to 4.10.3, the number of failed tests falls from all to only 5. :-) It is OK to add an @Ignore to these 5 unit tests, and create an issue so that someone can fix them in the future.

@nicolas-raoul
Copy link
Member

Now would be a great time to merge this.
Sorry for the delay, but would you mind rebasing (or pulling) from the latest main branch?
Thanks a lot!

sivaraam added a commit that referenced this pull request Oct 15, 2023
This is as per the observation of Nicolas Raoul in the MR. He mentions
this brings down test failures to just 5.

Ref: #5220 (comment)
@nicolas-raoul
Copy link
Member

I successfully uploaded a picture using prodRelease of this branch:
https://commons.wikimedia.org/wiki/File:March_2007_night_in_Valetta_9.jpg

@nicolas-raoul
Copy link
Member

The next task is to fix the unit tests, they all fail with this stacktrace:

 fr.free.nrw.commons.AboutActivityUnitTests > checkActivityNotNull FAILED
    org.mockito.exceptions.base.MockitoException at TestCommonsApplication.kt:81
        Caused by: org.mockito.exceptions.base.MockitoException at TypeCache.java:152
            Caused by: java.lang.IllegalStateException at InlineBytecodeGenerator.java:177
                Caused by: java.lang.IllegalArgumentException at ClassReader.java:184

Updating jacoco.gradle's toolVersion to 0.8.10 does not fix them.
In app/build.gradle I see that we are using 2.* mockito packages, while the latest versions seem to be 5.*, time to update maybe?

How about releasing a beta right now even though the unit tests fail? By doing so, we give more time to testers while we fix the unit tests (thus allowing us to shorten a bit the final beta test phase).

@sivaraam
Copy link
Member

sivaraam commented Oct 16, 2023

How about releasing a beta right now even though the unit tests fail? By doing so, we give more time to testers while we fix the unit tests (thus allowing us to shorten a bit the final beta test phase).

Ok Nicolas. Let us keep the changes of this MR in a separate release branch and release the beta from there. We could merge to main once we've fixed the unit tests. Right now the v4.2.0-release has all the changes of this MR. Let's use the same 👍🏼

@nicolas-raoul
Copy link
Member

Sounds good, thanks! :-)

@sivaraam sivaraam changed the base branch from main to v4.2.0-release October 17, 2023 02:28
@sivaraam sivaraam merged commit 26eaa46 into commons-app:v4.2.0-release Oct 17, 2023
@sivaraam
Copy link
Member

sivaraam commented Oct 17, 2023

Thanks a lot for contributing this change @siva-subramaniam-v ! It helped much for the release of the app 🙂

For the note, we're looking to address the unit test failures as a separate issue (#5339)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gradle build fails with Android Studio Flamingo update
4 participants