Normalize Java SDK (JDK) location logic across the tool#124152
Normalize Java SDK (JDK) location logic across the tool#124152andrewkolos wants to merge 8 commits intoflutter:masterfrom
Conversation
|
|
||
| String? _javaPath; | ||
|
|
||
| String? get javaHome => _javaPath ??= findJavaHome( |
There was a problem hiding this comment.
This is going to lead to a lot more implicit context accesses, does this need to be global?
There was a problem hiding this comment.
Or, can't we just have whatever needs to access this directly invoke findJavaHome?
|
Added a comment to the tracking issue: #122609 (comment) |
|
I marked this as ready-for-review since @christopherfujino has added reviewers--though tests are still needed. Based on continued discussion on #122609, a simpler change that could be made instead of this one is simply to remove the macOS-specific logic in Footnotes |
Per this and offline discussion with @christopherfujino, I will make a simpler PR that just removes the macOS-specific logic. This will make code review simpler and cherrypicking easier, which is ideal since we want this change sooner rather than later. Will post another comment with the new PR. |
|
Opened #124233 |
Thanks! I still think it's worth landing this refactor, but we can do that once the minimal "fix" has landed. |
|
I agree. I will set a reminder to open a tech-debt issue since JDK-finding is still fundamentally confusing at a flutter tool code level |
That's an understatement :) |
Fixes #122609.
Related: #123643.
Tangentially related: #122376. (there are probably more issues than this--I need to look around)
CC: @christopherfujino @reidbaker
Context
flutter doctor -vprints the path of thejavabinary that is presumably used for all Android-related features (building apps, managing emulators, etc.). However, this logic is different from that used in other places tool outside offlutter doctor, which makes it possible for the JDK path thatflutter doctorlists to be different from the one that flutter actually uses when building Android apps. See this comment on #122609 from Greg and this comment from me on #122609 for more info.This has the potential to be confusing to those debugging build issues in android-enabled flutter projects.
Change
This change normalizes the logic of JDK-location across the tool. Said another way, any feature that needs to find a JDK installation will use the same logic to do so. The code that implements this logic is also lightly refactored.
To-do
/usr/libexec/java_homeon macOS systems, which was consulted as a second-to-last resort when finding the JDK to use for everything except invoking gradle.Pre-launch Checklist
Pre-launch Checklist
///).