Skip to content

Commit df90bb5

Browse files
author
Mubarak Imam
authored
fix issue with multiple java runtimes on macOS (flutter#52474)
1 parent c6665e4 commit df90bb5

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

packages/flutter_tools/lib/src/android/android_sdk.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,14 +583,13 @@ class AndroidSdk {
583583
if (platform.isMacOS) {
584584
try {
585585
final String javaHomeOutput = processUtils.runSync(
586-
<String>['/usr/libexec/java_home'],
586+
<String>['/usr/libexec/java_home', '-v', '1.8'],
587587
throwOnError: true,
588588
hideStdout: true,
589589
).stdout.trim();
590590
if (javaHomeOutput != null) {
591-
final List<String> javaHomeOutputSplit = javaHomeOutput.split('\n');
592-
if ((javaHomeOutputSplit != null) && (javaHomeOutputSplit.isNotEmpty)) {
593-
final String javaHome = javaHomeOutputSplit[0].trim();
591+
if ((javaHomeOutput != null) && (javaHomeOutput.isNotEmpty)) {
592+
final String javaHome = javaHomeOutput.split('\n').last.trim();
594593
return fileSystem.path.join(javaHome, 'bin', 'java');
595594
}
596595
}

packages/flutter_tools/test/general.shard/android/android_sdk_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void main() {
9898
.thenReturn(ProcessResult(1, 0, '26.1.1\n', ''));
9999
if (globals.platform.isMacOS) {
100100
when(globals.processManager.runSync(
101-
<String>['/usr/libexec/java_home'],
101+
<String>['/usr/libexec/java_home', '-v', '1.8'],
102102
workingDirectory: anyNamed('workingDirectory'),
103103
environment: anyNamed('environment'),
104104
)).thenReturn(ProcessResult(0, 0, '', ''));
@@ -137,7 +137,7 @@ void main() {
137137
.thenReturn(ProcessResult(1, 1, '26.1.1\n', 'Mystery error'));
138138
if (globals.platform.isMacOS) {
139139
when(globals.processManager.runSync(
140-
<String>['/usr/libexec/java_home'],
140+
<String>['/usr/libexec/java_home', '-v', '1.8'],
141141
workingDirectory: anyNamed('workingDirectory'),
142142
environment: anyNamed('environment'),
143143
)).thenReturn(ProcessResult(0, 0, '', ''));

0 commit comments

Comments
 (0)