Skip to content

[tools] Tool will likely not find the JDK bundled with the next major version of AndroidStudio (e.g. 2023) #125246

@andrewkolos

Description

@andrewkolos

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:

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:

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

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

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listtoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions