-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[Android] Catch and rethrow Java/Gradle incompatibility error #124084
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
@reidbaker This is my attempt at catching the error we talked about. It solidly does not work for me because the error I get from my repro:
makes the build fail before it even gets to the point of trying to build the app. Not sure if you have time but if @gmackall or anyone else you know has been able to repro it the way you did, I would greatly appreciate someone trying it out! |
packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
Outdated
Show resolved
Hide resolved
Does this mean the failure happens too early for the error regex code to run? |
Co-authored-by: Reid Baker <hamilton.reid.baker@gmail.com>
Co-authored-by: Reid Baker <hamilton.reid.baker@gmail.com>
I asked @christopherfujino about this, and seems like it was a caching issue on my end. Can verify it works! |
packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
Outdated
Show resolved
Hide resolved
packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
Outdated
Show resolved
Hide resolved
.childDirectory('android') | ||
.childFile('build.gradle'); | ||
globals.printBox( | ||
"${globals.logger.terminal.warningMark} Your project's Gradle and AGP 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.
@reidbaker should this also mention flutter analyze --suggestions
?
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.
obviously, this would mean this must land after your other change
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.
Not unless my pr lands before yours which I think is unlikely.
Co-authored-by: Christopher Fujino <fujino@google.com>
…s_test.dart Co-authored-by: Christopher Fujino <fujino@google.com>
…s_test.dart Co-authored-by: Christopher Fujino <fujino@google.com>
@camsim99 sorry for some reason google didnt think my personal gmail had signed the CLA. I fixed that and if you rerun the check it should pass. |
Merging upstream to pick up a test fix that will resolve the Mac tool_integration_tests failure |
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.
Approve % comments.
.childFile('build.gradle'); | ||
globals.printBox( | ||
"${globals.logger.terminal.warningMark} Your project's Gradle and AGP version " | ||
'is incompatible with the Java version that Flutter is using.\n\n' |
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.
Incompatible with the Java version that Gradle is using.
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.
It's the Java version that Flutter is running Gradle with. Gradle is just using what's in either JAVA_HOME or PATH, which I think is more like "the Java version it was asked to use by its caller" than "the Java version it's deciding to use." So I think it makes sense for the message to own that on behalf of Flutter.
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.
@gnprice To clarify, are you suggesting the message say something more like "the Java version that the user asked Gradle to use" versus "the Java version that Gradle is using"?
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.
No, sorry, my use of quotes was confusing in this context. I think the message you have, with "the Java version that Flutter is using", is good.
Gradle is getting run on the JDK that Flutter chooses for running Gradle. In particular Flutter makes a choice to tell Gradle to use the JDK from Android Studio (when Flutter can find such a JDK.) There's good reason for that choice; I think it's usually the right choice, even when it leads to this error message (though in some circumstances it should be different, like #121501). But it is a choice. So when that choice Flutter is making causes annoyance for the user, the error message should own Flutter's responsibility for the choice.
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 think the message you have, with "the Java version that Flutter is using", is good.
(Or "had", I guess — it looks like it says "that Gradle is using" now, and my suggestion would be to change it back to "that Flutter is using". Or could make it something like "that Flutter is using for Gradle", if you want to be more specific in that direction.)
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.
Oh, I think "that Flutter is using for Gradle" is a happy medium
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.
That sounds good to me
.childDirectory('android') | ||
.childFile('build.gradle'); | ||
globals.printBox( | ||
"${globals.logger.terminal.warningMark} Your project's Gradle and AGP 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.
Not unless my pr lands before yours which I think is unlikely.
/// If an incompatible Java and Gradle versions error is caught, we expect an | ||
/// error specifying that the Java major class file version, one of | ||
/// https://javaalmanac.io/bytecode/versions/, is unsupported by Gradle. | ||
final RegExp _unsupportedClassFileMajorVersionPattern = RegExp(r'(?:Unsupported class file major version\s+([0-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.
Nit:
I believe this pattern could be simplified to
r'Unsupported class file major version\s+\d+'
In particular the parentheses around the [0-9] means we are still capturing it as a group.
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.
Left a small nit about the regex pattern but LGTM
Frob is having issues and the branch cut is today. Merging to get this in prior. |
…r#124084) Catches and re-throws Gradle error indicating that the Gradle version is incompatible with the Java version that Flutter is using to tell users how to fix the issue. Related issue: flutter#122376 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat --------- Co-authored-by: Reid Baker <hamilton.reid.baker@gmail.com> Co-authored-by: Christopher Fujino <fujino@google.com> Co-authored-by: Christopher Fujino <christopherfujino@gmail.com>
Catches and re-throws Gradle error indicating that the Gradle version is incompatible with the Java version that Flutter is using to tell users how to fix the issue.
Related issue: #122376
Pre-launch Checklist
///
).