Skip to content

Commit fab62ed

Browse files
committed
Improve Java detection, fix OSX warning
Some OSX versions were opening a dialog if Java was not installed, because we tested Java in $PATH, which is a stub that just opens a warning dialog telling you to install Java. We now avoid doing that on OSX. Based on the logic from Flutter: https://github.com/flutter/flutter/blob/026ee9756cbbf574fdb7fde1f420813ee340a5c0/packages/flutter_tools/lib/src/android/android_sdk.dart\#L408-L445
1 parent 7cec66d commit fab62ed

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/interceptors/jvm.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ type JvmTarget = { pid: string, name: string, interceptedByProxy: number | undef
1515
const javaBinPromise: Promise<string | false> = (async () => {
1616
// Check what Java binaries might exist:
1717
const javaBinPaths = [
18-
await getMacJavaHome(), // Magic Mac helper for exactly this
19-
!!process.env.JAVA_HOME && // $JAVA_HOME/bin/java is standard
18+
// $JAVA_HOME/bin/java is the way to explicitly configure this
19+
!!process.env.JAVA_HOME &&
2020
path.join(process.env.JAVA_HOME!!, 'bin', 'java'),
21-
(await commandExists('java')) && // Fallback to java in $PATH
21+
22+
// Magic Mac helper for exactly this, used if available
23+
await getMacJavaHome(),
24+
25+
// Fallback to $PATH, but not on Mac, where by default this is a "Install Java" dialog warning
26+
(await commandExists('java')) && process.platform !== "darwin" &&
2227
'java'
28+
29+
// In future, we could improve this by also finding & using the JVM from Android Studio. See
30+
// Flutter's implementation of logic required to do this:
31+
// https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/android/android_studio.dart
2332
].filter(p => !!p) as string[];
2433

2534
// Run a self test in parallel with each of them:

0 commit comments

Comments
 (0)