Skip to content

Commit

Permalink
fix: be able to read more complex buildToolsVersion definitions (#2531)
Browse files Browse the repository at this point in the history
Co-authored-by: Loïc DARDANT <[email protected]>
  • Loading branch information
dloic and Loïc DARDANT authored Nov 29, 2024
1 parent 1447731 commit 1f91b6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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

0 comments on commit 1f91b6d

Please sign in to comment.