Skip to content

Commit

Permalink
When searching for the JDK bundled with an unrecognized version of An…
Browse files Browse the repository at this point in the history
…droid Studio, assume the version to be the latest (#125247)

Fixes #125246 by restoring the intended behavior of #101862. That is, when searching for a JDK and we encounter an Android Studio version we don't recognize, assume it to be the latest version `flutter` is aware of.

Also does some light refactoring in the tests, like using test objects instead of referencing `globals`.
  • Loading branch information
andrewkolos authored Apr 21, 2023
1 parent 7d2669b commit cf76b24
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 89 deletions.
16 changes: 10 additions & 6 deletions packages/flutter_tools/lib/src/android/android_studio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class AndroidStudio {
bool _isValid = false;
final List<String> _validationMessages = <String>[];

/// The path of the JDK bundled with Android Studio.
///
/// This will be null if the bundled JDK could not be found or run.
String? get javaPath => _javaPath;

bool get isValid => _isValid;
Expand Down Expand Up @@ -487,16 +490,17 @@ the configured path by running this command: flutter config --android-studio-dir
if (globals.platform.isMacOS) {
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 {
} else if (version != null && version!.major < 2022) {
javaPath = globals.fs.path.join(directory, 'jre', 'Contents', 'Home');
// See https://github.com/flutter/flutter/issues/125246 for more context.
} else {
javaPath = globals.fs.path.join(directory, 'jbr', 'Contents', 'Home');
}
} else {
if (version != null && version!.major == 2022) {
javaPath = globals.fs.path.join(directory, 'jbr');
} else {
if (version != null && version!.major < 2022) {
javaPath = globals.fs.path.join(directory, 'jre');
} else {
javaPath = globals.fs.path.join(directory, 'jbr');
}
}
final String javaExecutable = globals.fs.path.join(javaPath, 'bin', 'java');
Expand Down
Loading

0 comments on commit cf76b24

Please sign in to comment.