-
Notifications
You must be signed in to change notification settings - Fork 28.6k
fix issue with multiple java runtimes on macOS #52474
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
fix issue with multiple java runtimes on macOS #52474
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@mimam419 If you'd like to continue with this PR, please follow the instructions of the fluttergithubbot and the googlebot. Thanks! |
Hi @zanderso, I am having difficulties fixing the tests because I am quite new to flutter. Would you mind guiding me on how to get that sorted? Thank you. |
@@ -583,14 +583,13 @@ class AndroidSdk { | |||
if (platform.isMacOS) { | |||
try { | |||
final String javaHomeOutput = processUtils.runSync( | |||
<String>['/usr/libexec/java_home'], | |||
<String>['/usr/libexec/java_home', '-v', '1.8'], |
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.
At a glance, this does not seem very future proof. Should this not specify a version, and take the most recent available instead? /cc @blasten for thoughts.
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.
My initial thought too, but then I realized the error was due to the fact that the tooling was picking the latest version, and it fails whenever that latest version is not v1.8, hence my reason for this approach.
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.
do you remember which version java_home
was defaulting to?
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.
For example, it defaults to 1.13 on my machine, which obviously do not work in flutter.
The first solution was uninstalling other versions of Java, then it would pick 1.8
Basically, it pick the latest version of java based on the output from java_home
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.
Thanks for the background information. One more question, did you ever get an error message other than the Flutter doctor failure? I wonder if there are related issues that can be associated with this fix.
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 did not get any other errors.
In fact, the original error was that "android-sdk" was not installed, after reading through similar errors from here and StackOverflow, I learned it was due to not having the right version of JDK (v1.8) installed.
See also #9429 |
if ((javaHomeOutputSplit != null) && (javaHomeOutputSplit.isNotEmpty)) { | ||
final String javaHome = javaHomeOutputSplit[0].trim(); | ||
if ((javaHomeOutput != null) && (javaHomeOutput.isNotEmpty)) { | ||
final String javaHome = javaHomeOutput.trim(); |
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 still needs to split by lines and javaHome
is the last line instead of the first one. This is to account for a case where java 1.8 isn't installed. The first line becomes an error message.
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.
Here is how the scenario went here.
I have two versions of java v1.8
and v1.13
installed.
Having set v1.8
as my default version via jenv
, running java -version
returns
Running the original code /usr/libexec/java_home
returns
The next viable option would have been running /usr/libexec/java_home -V
, which returns
Picking the right java_home
address there is tricky, and as you can see, even the last line has v1.13
.
Since flutter
would not accept any other version of java
except 1.8
(at least for now).
I feel it is okay to try /usr/libexec/java_home -v 1.8
, which returns
Just what we need and nothing more.
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.
LG after the comment is addressed + the test added
I was having difficulty running the test locally, but I have managed to proceed now. |
6be9ece
to
a38d5d5
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Hello @blasten, the tests are also fixed now. |
a38d5d5
to
9caaec7
Compare
if ((javaHomeOutputSplit != null) && (javaHomeOutputSplit.isNotEmpty)) { | ||
final String javaHome = javaHomeOutputSplit[0].trim(); | ||
if ((javaHomeOutput != null) && (javaHomeOutput.isNotEmpty)) { | ||
final String javaHome = javaHomeOutput.trim(); |
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.
final String javaHome = javaHomeOutput.trim(); | |
final String javaHome = javaHomeOutput.split('\n').last.trim(); |
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.
Running java_home -v 999999
, outputs:
Unable to find any JVMs matching version "999999".
/Library/Java/JavaVirtualMachines/openjdk-12.0.1.jdk/Contents/Home
Therefore, it needs to extract the last line, which is the default JVM.
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.
Hello @blasten, you are suggesting this as a fix for when Java 8 is not installed?
I just understood your point, the requested changes have been effected.
Thank you.
- specify java v1.8 in call to java_home
- added tests to handle the modificstion
9caaec7
to
003e327
Compare
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.
LGTM
Thanks for the contribution! |
Description
Flutter developers on macOS with multiple JVM installations encounter an issue where flutter reports an installation error with the installed Android SDK.
I found out that this was due to how Flutter looks for the JDK on macOS.
Below is a screenshot of what the error looks like, and the results after this fix.
Related Issues
Replace this paragraph with a list of issues related to this PR from our issue database. Indicate, which of these issues are resolved or fixed by this PR. There should be at least one issue listed here.
Tests
I added the following tests:
Replace this with a list of the tests that you added as part of this PR. A change in behaviour with no test covering it
will likely get reverted accidentally sooner or later. PRs must include tests for all changed/updated/fixed behaviors. See Test Coverage.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read Handling breaking changes.