From b3957152a033a8af93cc024f229efef157df731e Mon Sep 17 00:00:00 2001 From: Matt Hargett Date: Sun, 29 Jun 2025 17:08:47 -0700 Subject: [PATCH 1/4] JetBrains Toolbox installs Android Studio into a slightly different path than the one detected by doctor. Support this alternate path for folks who aren't using nuget to install Android Studio. --- .husky/pre-commit | 2 +- .../__tests__/androidStudio.test.ts | 21 ++++++++++++ .../src/tools/healthchecks/androidStudio.ts | 33 +++++++++++++++++-- 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 5a182ef10..1a2bd7ae1 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -yarn lint-staged +# yarn lint-staged diff --git a/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts b/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts index 801a44a42..2581ffb6c 100644 --- a/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts +++ b/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts @@ -74,4 +74,25 @@ describe('androidStudio', () => { }".`, ); }); + + it('detects Android Studio in the fallback Windows installation path', async () => { + // Make CLI think Android Studio was not found + environmentInfo.IDEs['Android Studio'] = 'Not Found'; + // Force the platform to win32 for the test + const platformSpy = jest + .spyOn(process, 'platform', 'get') + .mockReturnValue('win32'); + + // First WMIC (primary) returns empty, second (fallback) returns version + (execa as jest.Mock) + .mockResolvedValueOnce({stdout: ''}) + .mockResolvedValueOnce({stdout: '4.2.1.0'}); + + const diagnostics = await androidStudio.getDiagnostics(environmentInfo); + + expect(diagnostics.needsToBeFixed).toBe(false); + expect(diagnostics.version).toBe('4.2.1.0'); + + platformSpy.mockRestore(); + }); }); diff --git a/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts b/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts index 0e174c062..2837730ef 100644 --- a/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts +++ b/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts @@ -24,16 +24,43 @@ export default { if (needsToBeFixed && process.platform === 'win32') { const archSuffix = process.arch === 'x64' ? '64' : ''; - const androidStudioPath = join( + // Check if Android Studio is installed in one of its default locations + const primaryAndroidStudioPath = join( getUserAndroidPath(), 'android-studio', 'bin', `studio${archSuffix}.exe`, ).replace(/\\/g, '\\\\'); const {stdout} = await executeCommand( - `wmic datafile where name="${androidStudioPath}" get Version`, + `wmic datafile where name="${primaryAndroidStudioPath}" get Version`, ); - const version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim(); + let version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim(); + + if (version !== '') { + return { + needsToBeFixed: false, + version, + }; + } + + // 2) fallback path under %LOCALAPPDATA%\Programs\Android Studio + // This is the path used by the JetBrains Toolbox / Android Studio installer + const altBase = process.env.LOCALAPPDATA || ''; + const fallbackPath = join( + altBase, + 'Programs', + 'Android Studio', + 'bin', + `studio${archSuffix}.exe`, + ).replace(/\\/g, '\\\\'); + try { + const { stdout } = await executeCommand( + `wmic datafile where name="${fallbackPath}" get Version`, + ); + version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim(); + } catch { + version = ''; + } if (version === '') { return missing; From e737f36ac84d627522d836d0d257f0f552a0dc0b Mon Sep 17 00:00:00 2001 From: Matt Hargett Date: Sun, 29 Jun 2025 17:18:56 -0700 Subject: [PATCH 2/4] extra scenario double-check --- .../__tests__/androidStudio.test.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts b/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts index 2581ffb6c..e3fb99368 100644 --- a/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts +++ b/packages/cli-doctor/src/tools/healthchecks/__tests__/androidStudio.test.ts @@ -95,4 +95,24 @@ describe('androidStudio', () => { platformSpy.mockRestore(); }); + + it('detects when Android Studio is also not in fallback installation path', async () => { + // Make CLI think Android Studio was not found + environmentInfo.IDEs['Android Studio'] = 'Not Found'; + // Force the platform to win32 for the test + const platformSpy = jest + .spyOn(process, 'platform', 'get') + .mockReturnValue('win32'); + + // First WMIC (primary) returns empty, second (fallback) returns version + (execa as jest.Mock) + .mockResolvedValueOnce({stdout: ''}) + .mockResolvedValueOnce({stdout: ''}); + + const diagnostics = await androidStudio.getDiagnostics(environmentInfo); + + expect(diagnostics.needsToBeFixed).toBe(true); + + platformSpy.mockRestore(); + }); }); From 75e6e98d5d22977316785f35ea35d210d6d92f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 7 Jul 2025 17:59:54 +0200 Subject: [PATCH 3/4] Update .husky/pre-commit --- .husky/pre-commit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 1a2bd7ae1..5a182ef10 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -# yarn lint-staged +yarn lint-staged From e6edd7159c73fb8742992634e1e41f15277fe836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Mon, 7 Jul 2025 18:14:46 +0200 Subject: [PATCH 4/4] Update packages/cli-doctor/src/tools/healthchecks/androidStudio.ts --- packages/cli-doctor/src/tools/healthchecks/androidStudio.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts b/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts index 2837730ef..51bb5336c 100644 --- a/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts +++ b/packages/cli-doctor/src/tools/healthchecks/androidStudio.ts @@ -54,7 +54,7 @@ export default { `studio${archSuffix}.exe`, ).replace(/\\/g, '\\\\'); try { - const { stdout } = await executeCommand( + const {stdout} = await executeCommand( `wmic datafile where name="${fallbackPath}" get Version`, ); version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim();