-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
issue_link
Commit Hash
Target
stable
pr_link
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
- upgrade to the Android Studio 'Flamingo' stable version released this month (or are otherwise using a newer version).
- last ran
flutter createover ~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
- Ensure that your android studio version is at least the latest stable ('Flamingo', or 2022.2.1).
- Using a version of flutter older than 3.0 (so 2.10.5 for example, commit hash 5464c5b), run
flutter create. - 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 runwith 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. │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────┘
- Switch to using a version of flutter containing this fix (e.g. master).
- Run
flutter runand look for a log message noting that your gradle version is being upgraded*. - 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 runactually 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 thisflutter runsucceeds.