Skip to content
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

fix: be able to read more complex buildToolsVersion definitions #2531

Merged
merged 1 commit into from
Nov 29, 2024
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 number Diff line number Diff line change
Expand Up @@ -75,6 +75,29 @@ describe('androidSDK', () => {
expect(diagnostics.needsToBeFixed).toBe(true);
});

it('reads buildToolsVersion when using more complex definition', async () => {
// Override mock file
writeFiles(mockWorkingDir, {
'android/build.gradle': `
buildscript {
ext {
buildToolsVersion = findProperty('android.buildToolsVersion') ?: '34.0.0'
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
}
}
`,
});
// @ts-ignore
environmentInfo.SDKs['Android SDK'] = {
'Build Tools': ['34.0.0'],
};
(execa as unknown as jest.Mock).mockResolvedValue({stdout: ''});
const diagnostics = await androidSDK.getDiagnostics(environmentInfo);
expect(diagnostics.needsToBeFixed).toBe(false);
});

it('returns false if the SDK version is in range', async () => {
// To avoid having to provide fake versions for all the Android SDK tools
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions packages/cli-doctor/src/tools/healthchecks/androidSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const getBuildToolsVersion = (projectRoot = ''): string => {
// Get only the portion of the declaration of `buildToolsVersion`
.substring(buildToolsVersionIndex)
.split('\n')[0]
// Get only the the value of `buildToolsVersion`
.match(/\d|\../g) || []
).join('');
// Get only the value of `buildToolsVersion`
.match(/\d+\.\d+\.\d+/g) || []
).at(0);

return buildToolsVersion || 'Not Found';
};
Expand Down
Loading