Skip to content
Merged
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 numberDiff line numberDiff line change
Expand Up@@ -74,4 +74,65 @@ 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 platform to win32 for the test
// TODO: use cleaner jest.replaceProperty in jest 29+
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {
value: 'win32',
writable: true,
configurable: true,
});

// First WMIC (primary) returns empty, second (fallback) returns version
(execa as unknown 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');

// Restore original platform
// TODO: use cleaner mockRestore in jest 29+
Object.defineProperty(process, 'platform', {
value: originalPlatform,
writable: true,
configurable: true,
});
});

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
// TODO: use cleaner jest.replaceProperty in jest 29+
const originalPlatform = process.platform;
Object.defineProperty(process, 'platform', {
value: 'win32',
writable: true,
configurable: true,
});

// First WMIC (primary) returns empty, second (fallback) returns version
(execa as unknown as jest.Mock)
.mockResolvedValueOnce({stdout: ''})
.mockResolvedValueOnce({stdout: ''});

const diagnostics = await androidStudio.getDiagnostics(environmentInfo);

expect(diagnostics.needsToBeFixed).toBe(true);

// Restore original platform
// TODO: use cleaner mockRestore in jest 29+
Object.defineProperty(process, 'platform', {
value: originalPlatform,
writable: true,
configurable: true,
});
});
});
33 changes: 30 additions & 3 deletions packages/cli-doctor/src/tools/healthchecks/androidStudio.ts
Original file line numberDiff line numberDiff 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