这是indexloc提供的服务,不要输入任何密码
Skip to content

[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

Merged
merged 22 commits into from
Apr 5, 2023

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Apr 4, 2023

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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 4, 2023
@camsim99
Copy link
Contributor Author

camsim99 commented Apr 4, 2023

@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:

* Where:
Build file '.../my_app/android/build.gradle' line: 26

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > Could not open proj generic class cache for build file '.../my_app/android/app/build.gradle' (.../.gradle/caches/6.7/scripts/4tzbic373izz50a4nwuxhhr6k).
      > BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 61

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!

@reidbaker
Copy link
Contributor

generic class cache for build

Does this mean the failure happens too early for the error regex code to run?

@camsim99 camsim99 marked this pull request as ready for review April 4, 2023 18:02
@camsim99
Copy link
Contributor Author

camsim99 commented Apr 4, 2023

Does this mean the failure happens too early for the error regex code to run?

I asked @christopherfujino about this, and seems like it was a caching issue on my end. Can verify it works!

.childDirectory('android')
.childFile('build.gradle');
globals.printBox(
"${globals.logger.terminal.warningMark} Your project's Gradle and AGP version "
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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.

camsim99 and others added 3 commits April 4, 2023 12:22
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 camsim99 requested a review from reidbaker April 4, 2023 19:54
@reidbaker
Copy link
Contributor

@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.

@christopherfujino
Copy link
Contributor

Merging upstream to pick up a test fix that will resolve the Mac tool_integration_tests failure

Copy link
Contributor

@reidbaker reidbaker left a 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'
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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"?

Copy link
Member

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.

Copy link
Member

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.)

Copy link
Contributor Author

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

Copy link
Contributor

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 "
Copy link
Contributor

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]+))');
Copy link
Member

@gmackall gmackall Apr 5, 2023

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.

Copy link
Member

@gmackall gmackall left a 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

@camsim99
Copy link
Contributor Author

camsim99 commented Apr 5, 2023

Frob is having issues and the branch cut is today. Merging to get this in prior.

@camsim99 camsim99 merged commit 87392c2 into flutter:master Apr 5, 2023
exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants