Skip to content
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

deps android: Upgrade Android Gradle Plugin #887

Merged
merged 5 commits into from
Aug 15, 2024

Conversation

rajveermalviya
Copy link
Collaborator

Fixes: #879

@rajveermalviya rajveermalviya added the integration review Added by maintainers when PR may be ready for integration label Aug 12, 2024
Copy link
Member

@gnprice gnprice 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 care of this!

I read through all the linked release notes (well, skimming over the parts that seem irrelevant to us like Kotlin/Native), and these all make sense to me. I took some additional notes for a couple of the commits, which I'll push as a revision.

It looks like I'll have to upgrade my Android Studio before I can test this locally (I'm currently on Hedgehog). Is the last commit, the AGP upgrade, the one that fixes #879? Let's mention that in the commit message.


compileOptions {
coreLibraryDesugaringEnabled true
Copy link
Member

Choose a reason for hiding this comment

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

android build: Enable core library desugaring for
flutter_local_notifications

commit-message nit: summary on one line

Though separately, this reads to me like it's saying it's enabling that option only to apply to that library — that's what "enable foo for bar" normally means to me. Could replace " for" by ", needed by"… or even just by ", for".

Copy link
Member

Choose a reason for hiding this comment

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

oh and separate nit:

This applies the Android setup steps required for
package:flutter_local_notification [1], enabling core library

the package's name is plural

agpVersion=8.1.4
agpVersion=8.5.0
Copy link
Member

Choose a reason for hiding this comment

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

Ah I see, we hadn't been neglecting these upgrades so much as I thought at #879 (comment) — I just wasn't looking at the right file's history. 🙂 That makes more sense.

@@ -23,9 +23,9 @@ android {
namespace "com.zulip.flutter"

compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
Copy link
Member

@gnprice gnprice Aug 13, 2024

Choose a reason for hiding this comment

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

android build: Avoid specifying ndkVersion explicitly

This commit message needs a bit more explanation, so that our future selves and/or successors reading this a couple of years from now when the question of the NDK version comes up again don't have to wonder what we were thinking or sleuth it out.

I'll write a version. → 2e59090

@rajveermalviya
Copy link
Collaborator Author

Thanks for the review @gnprice, pushed a new revision PTAL.

@@ -6,11 +6,11 @@ android.enableJetifier=true
# Defining them here makes them available both in
# settings.gradle and in the build.gradle files.

agpVersion=8.1.4
agpVersion=8.5.0
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to go for 8.5.0 instead of 8.5.2? It looks like that's the latest.

(My usual approach would be to go for the latest patch release within a given minor release, even when holding back at an older minor or major release for whatever reason.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a reason to go for 8.5.0 instead of 8.5.2?

Not really, hadn't realized there was a newer one, I just took that version from release notes.
Updated now to 8.5.2.

@gnprice
Copy link
Member

gnprice commented Aug 14, 2024

OK, I upgraded my Android Studio so I could build this, and confirmed that it fixes #879 (and that I can reproduce that before this PR).

I'm seeing also this warning on flutter run:

$ flutter run --release -d p
Launching lib/main.dart on Pixel 8 in release mode...
Info: Proguard configuration rule does not match anything: `-keepclassmembers class j$.util.concurrent.ConcurrentHashMap$TreeBin {
  int lockState;
}`
Info: Proguard configuration rule does not match anything: `-keepclassmembers class j$.util.concurrent.ConcurrentHashMap {
  int sizeCtl;
  int transferIndex;
  long baseCount;
  int cellsBusy;
}`
Info: Proguard configuration rule does not match anything: `-keepclassmembers class j$.util.concurrent.ConcurrentHashMap$CounterCell {
  long value;
}`
Info: Proguard configuration rule does not match anything: `-keepclassmembers enum * {
  public static **[] values();
  public static ** valueOf(java.lang.String);
  public static final synthetic <fields>;
}`
Info: Proguard configuration rule does not match anything: `-keepclassmembers class j$.util.IntSummaryStatistics {
  long count;
  long sum;
  int min;
  int max;
}`
Info: Proguard configuration rule does not match anything: `-keepclassmembers class j$.util.LongSummaryStatistics {
  long count;
  long sum;
  long min;
  long max;
}`
Info: Proguard configuration rule does not match anything: `-keepclassmembers class j$.util.DoubleSummaryStatistics {
  long count;
  double sum;
  double min;
  double max;
}`
Running Gradle task 'assembleRelease'...                           58.0s

Not catastrophic if we have to live with those warnings for a bit, but it is somewhat annoying. Would you spend a bit of time investigating that and trying to find a fix?

@gnprice
Copy link
Member

gnprice commented Aug 14, 2024

Also confirmed that #879 reproduces just before the last commit, so it is that commit (the AGP upgrade) that fixes it.

(As a side effect I learned that that next-to-last commit already has the warning above, so whatever introduces that comes before the last commit.)

@rajveermalviya
Copy link
Collaborator Author

rajveermalviya commented Aug 14, 2024

seeing warnings on flutter run

...
Info: Proguard configuration rule does not match anything: `-keepclassmembers class j$.util.concurrent.ConcurrentHashMap$TreeBin {
...

I only got that after a flutter clean, doesn't seem to printed in subsequent runs of flutter run, guess it's because of caching. Also it seems it has been reported upstream to be a com.android.tools:desugar_jdk_libs issue — https://issuetracker.google.com/issues/294273986

@rajveermalviya rajveermalviya changed the title deps android: Upgrade Android Gradle Plugin to 8.5.0 deps android: Upgrade Android Gradle Plugin Aug 14, 2024
@rajveermalviya
Copy link
Collaborator Author

Thanks for the review @gnprice, pushed a new revision, PTAL.

Release notes:
  https://docs.gradle.org/8.7/release-notes.html
  https://docs.gradle.org/8.8/release-notes.html
  https://docs.gradle.org/8.9/release-notes.html

Some highlights:
  * 8.7 "Support for building projects with Java 22"
  * 8.8 "Full Java 22 support"
  * 8.9 "Error and warning reporting improvements"

[greg: One other notable theme in the 8.7 and 8.8 release notes
 is caching improvements.  Hopefully our builds might get faster.]
Release notes:
  https://kotlinlang.org/docs/whatsnew1920.html
  https://kotlinlang.org/docs/whatsnew20.html

Highlights:

* 1.9.20
  - Standard library; Improvements to the Atomics API.
  - Otherwise mostly related to Wasm, Native and Kotlin
    Multiplatform.

* 2.0.0
  - Enables the new unified K2 compiler by default on all
    targets.
  - Language; Smarter type-casting
  -
  - JVM; better bytecode for lambda enabled by default, which
    reduces the binary size.
  - Standard Library; AutoCloseable interface
  - Many more to list here.
@gnprice
Copy link
Member

gnprice commented Aug 15, 2024

I only got that after a flutter clean, doesn't seem to printed in subsequent runs of flutter run, guess it's because of caching.

Yeah, that seems to be how warnings in Android builds often behave. It can be annoying when trying to debug and eliminate the warnings, because it makes it tricky to confidently reproduce them… but it does also mitigate the impact of the warning noise somewhat.

Also it seems it has been reported upstream to be a com.android.tools:desugar_jdk_libs issue — https://issuetracker.google.com/issues/294273986

Cool, thanks for tracking that down. I upvoted the issue and subscribed. Looks like it's been there a year, which is less promising than if it were just recently filed; but it also lacks a repro, so after merging this I'll comment there offering zulip-flutter as a repro, and potentially that'll help get it fixed.

That also means the coreLibraryDesugaring commit must be the one that introduces the warning. I'll add a comment at that line, and a note in #351, that once we remove flutter_local_notifications we can try removing that step.

…l_notifications

This applies an Android setup step called for
by package:flutter_local_notifications:
  https://github.com/MaikuB/flutter_local_notifications/tree/d565daab613052fecaf723df865101b46ee5a26a/flutter_local_notifications#gradle-setup

namely enabling core-library desugaring:
  https://developer.android.com/studio/write/java8-support#library-desugaring

We seem to have been fine without that step so far.  But after the
upcoming upgrade to AGP 8.5.2 (from 8.1.4), the build starts giving
an error demanding this change:

Execution failed for task ':app:checkReleaseAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > An issue was found when checking AAR metadata:

       1.  Dependency ':flutter_local_notifications' requires core library desugaring to be enabled
           for :app.

           See https://developer.android.com/studio/write/java8-support.html for more
           details.

[greg: expanded commit message, added comment]
Specifying the NDK version here doesn't seem to do us any good.

This value provided by the `flutter` tool is currently 23.1.7779620.
If we upgrade the Android Gradle plugin (AGP) to 8.5.2, its current
latest, then we start getting build warnings:
  zulip#879 (comment)
saying that a bunch of plugins -- including first-party plugins -- are
all using NDK 26.1.10909125 instead, and telling us to switch to that.

Conversely, if we leave this line out, then the same AGP upgrade
causes no warnings and works just fine.

So let the version float.  This does contradict AGP's own recommendation:
  https://developer.android.com/studio/projects/configure-agp-ndk
which is to use this `ndkVersion` property.  But if a bunch of our
plugins are going to use a floating version anyway, it doesn't seem
helpful to try to hang back.

[greg: added commit-message body]
Release notes:
  https://developer.android.com/build/releases/past-releases/agp-8-2-0-release-notes
  https://developer.android.com/build/releases/past-releases/agp-8-3-0-release-notes
  https://developer.android.com/build/releases/past-releases/agp-8-4-0-release-notes
  https://developer.android.com/build/releases/gradle-plugin (for 8.5, for now)

Some of the release notes (especially 8.2) are very thin; it's not
clear if there are other changes that aren't being described, or if
they just didn't change much.

Changes possibly affecting us:
 * 8.3 adds "precise resource shrinking", which seems to be an
   additional form of resource shrinking.
 * As usual, a new AGP version requires a new Android Studio version.
   AGP 8.5 requires Android Studio Koala.

[greg: added reading of release notes]

Fixes: zulip#879
@gnprice gnprice merged commit 1bea14d into zulip:main Aug 15, 2024
1 check passed
@rajveermalviya rajveermalviya deleted the pr-update-agp branch August 16, 2024 05:48
@gnprice
Copy link
Member

gnprice commented Oct 27, 2024

a com.android.tools:desugar_jdk_libs issue — https://issuetracker.google.com/issues/294273986

Following up on this: my comment prompted that thread to get closed as a duplicate, and it turns out that the bug had been fixed (in that library's main branch) just a couple of days earlier:
https://issuetracker.google.com/issues/358166486#comment8

So eventually that'll filter into AGP, and then into an AGP release that we upgrade to.

Meanwhile we're about to complete #351 removing package:flutter_local_notifications, so that PR #856 is removing this desugaring step anyway as hoped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration review Added by maintainers when PR may be ready for integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash on Android when tapping on camera icon in compose box, in release mode
2 participants