fix issue with multiple java runtimes on macOS (#52474)

This commit is contained in:
Mubarak Imam 2020-03-31 19:36:01 +01:00 committed by GitHub
parent c6665e43da
commit df90bb5fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View File

@ -583,14 +583,13 @@ class AndroidSdk {
if (platform.isMacOS) {
try {
final String javaHomeOutput = processUtils.runSync(
<String>['/usr/libexec/java_home'],
<String>['/usr/libexec/java_home', '-v', '1.8'],
throwOnError: true,
hideStdout: true,
).stdout.trim();
if (javaHomeOutput != null) {
final List<String> javaHomeOutputSplit = javaHomeOutput.split('\n');
if ((javaHomeOutputSplit != null) && (javaHomeOutputSplit.isNotEmpty)) {
final String javaHome = javaHomeOutputSplit[0].trim();
if ((javaHomeOutput != null) && (javaHomeOutput.isNotEmpty)) {
final String javaHome = javaHomeOutput.split('\n').last.trim();
return fileSystem.path.join(javaHome, 'bin', 'java');
}
}

View File

@ -98,7 +98,7 @@ void main() {
.thenReturn(ProcessResult(1, 0, '26.1.1\n', ''));
if (globals.platform.isMacOS) {
when(globals.processManager.runSync(
<String>['/usr/libexec/java_home'],
<String>['/usr/libexec/java_home', '-v', '1.8'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(ProcessResult(0, 0, '', ''));
@ -137,7 +137,7 @@ void main() {
.thenReturn(ProcessResult(1, 1, '26.1.1\n', 'Mystery error'));
if (globals.platform.isMacOS) {
when(globals.processManager.runSync(
<String>['/usr/libexec/java_home'],
<String>['/usr/libexec/java_home', '-v', '1.8'],
workingDirectory: anyNamed('workingDirectory'),
environment: anyNamed('environment'),
)).thenReturn(ProcessResult(0, 0, '', ''));