Skip to content

[fix] Support Android Studio path that JetBrains Toolbox installs to on Windows #2682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,45 @@ 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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are failing here, can you investigate that?

.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();
});

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();
});
});
33 changes: 30 additions & 3 deletions packages/cli-doctor/src/tools/healthchecks/androidStudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,43 @@
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(

Check warning on line 57 in packages/cli-doctor/src/tools/healthchecks/androidStudio.ts

View workflow job for this annotation

GitHub Actions / Lint

'stdout' is already declared in the upper scope on line 34 column 14
`wmic datafile where name="${fallbackPath}" get Version`,
);
version = stdout.replace(/(\r\n|\n|\r)/gm, '').trim();
} catch {
version = '';
}

if (version === '') {
return missing;
Expand Down
Loading