-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Highly related to #121468.
Context
For accomplishing various JDK-dependent activities, like building Android apps and running Android SDK tools, the tool prefers to use a JDK bundled with Android Studio found on the host machine.
When running the flutter tool, it will look for Android Studio installations. For each installation, it looks for the bundled JDK in a path determined from the Android Studio version. The current code for this logic.
Issue
Starting with major version 2022, the location of the bundled JDK was changed for all three major desktop platforms. The tool was updated to be aware of this new location; however, the code matches exactly on the major version of 2022.
This means that, starting with major version 2023, the tool will start looking in the default location (which corresponds to versions 2020 and 2021 on macOS and all versions pre-2022 on Linux/Windows). This will break flutter for flutter-on-Android users unless they have another, older installation of Android Studio available.
Relevant code for macOS:
flutter/packages/flutter_tools/lib/src/android/android_studio.dart
Lines 488 to 494 in 68ec71f
| if (version != null && version!.major < 2020) { | |
| javaPath = globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home'); | |
| } else if (version != null && version!.major == 2022) { | |
| javaPath = globals.fs.path.join(directory, 'jbr', 'Contents', 'Home'); | |
| } else { | |
| javaPath = globals.fs.path.join(directory, 'jre', 'Contents', 'Home'); | |
| } |
Relevant code for Linux/Windows:
flutter/packages/flutter_tools/lib/src/android/android_studio.dart
Lines 496 to 500 in 68ec71f
| if (version != null && version!.major == 2022) { | |
| javaPath = globals.fs.path.join(directory, 'jbr'); | |
| } else { | |
| javaPath = globals.fs.path.join(directory, 'jre'); | |
| } |
Suggested fix
When faced with a version newer than the tool is explicitly aware of, it makes more sense to treat it as the newest version it is aware of1. This would be 2022 at this time.
Footnotes
-
Default to the newer version path when checking Android Studio Java path #101862 also suggests that this was the intended behavior. Alternatively, the tool could try each known JDK path. ↩