Skip to content

[CP] Cherry pick migrator to upgrade Gradle version when conflict with Android Studio bundled java is detected #125693

@gmackall

Description

@gmackall

issue_link

#122376

Commit Hash

eba2a52

Target

stable

pr_link

#126093

Impacted Users

Flutter android devs who haven't upgraded the Gradle version in their project in ~1 year, and have upgraded to the latest stable Android Studio version ('Flamingo', or 2022.2.1).

Impact Description

I would recommend looking at the issue that is linked from the PR (#122376) as it has a particularly good description of the impact, BUT with the important caveat that the original issue states that the error will be an inscrutable one of the form:

FAILURE: Build failed with an exception.

* Where:
Build file '…/example/android/build.gradle'

* What went wrong:
Could not compile build file '…/example/android/build.gradle'.
> startup failed:
  General error during conversion: Unsupported class file major version 61

  java.lang.IllegalArgumentException: Unsupported class file major version 61
  	at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:189)
  	at groovyjarjarasm.asm.ClassReader.<init>(ClassReader.java:170)
  	[…
  	 …
  	 … 209 more lines of Groovy and Gradle stack trace …
  	 …
  	 …]
  	at java.base/java.lang.Thread.run(Thread.java:833)

and this is actually no longer the case thanks to the work in: #124084. Rather the error will inform them of the actual issue, and provide a link to a flutter documentation page with mitigation steps.

The summary is that flutter run and flutter build for android will error for flutter devs who

  1. upgrade to the Android Studio 'Flamingo' stable version released this month (or are otherwise using a newer version).
  2. last ran flutter create over ~1 year ago, and haven't updated the gradle version in their gradle-wrapper.properties file since.

Workaround

Yes, the workaround would be for the devs to follow the migration steps and directly upgrade the gradle version in their gradle-wrapper.properties file.

Risk

high

Test Coverage

yes

Validation Steps

To validate that this fix works, it would be best to

  1. Ensure that your android studio version is at least the latest stable ('Flamingo', or 2022.2.1).
  2. Using a version of flutter older than 3.0 (so 2.10.5 for example, commit hash 5464c5b), run flutter create.
  3. For a quick sanity check: upgrade to a recent version of flutter that does not contain this fix (commit hash fc2098 for example) and run flutter run with an android device or emulator. You should see an error with output towards the bottom of
┌─ Flutter Fix ─────────────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using for Gradle. │
│                                                                                                           │
│ To fix this issue, consult the migration guide at docs.flutter.dev/go/android-java-gradle-error.          │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┘
  1. Switch to using a version of flutter containing this fix (e.g. master).
  2. Run flutter run and look for a log message noting that your gradle version is being upgraded*.
  3. Confirm by checking that the version of gradle in your gradle-wrapper.properties has been upgraded to 7.6.1 (from the root of your project, open ./android/gradle/wrapper/gradle-wrapper.properties and look at the line that starts with distributionUrl).
  • Note on step 5 - for me flutter run actually still failed, but for a separate issue that would have needed fixing afterwards in this example project regardless (in this case, changing the AGP version in android/build.gradle to a newer one, for example 7.3.0). After fixing this flutter run succeeds.

Metadata

Metadata

Assignees

Labels

cp: approvedApproved cherry-pick requestcp: merge-to-stableCherry-picks that should be merged to stablecp: reviewCherry-picks in the review queue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions