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
55 changes: 45 additions & 10 deletions packages/cli/src/commands/doctor/healthchecks/androidSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,52 @@ import chalk from 'chalk';
import {logManualInstallation} from './common';
import versionRanges from '../versionRanges';
import {doesSoftwareNeedToBeFixed} from '../checkInstallation';
import execa from 'execa';

const installMessage = `Read more about how to update Android SDK at ${chalk.dim(
'https://developer.android.com/studio',
)}`;

export default {
label: 'Android SDK',
getDiagnosticsAsync: async ({SDKs}) => ({
needsToBeFixed: doesSoftwareNeedToBeFixed({
version: SDKs['Android SDK']['Build Tools'][0],
versionRange: versionRanges.ANDROID_NDK,
}),
}),
getDiagnosticsAsync: async ({SDKs}) => {
let sdks = SDKs['Android SDK'];

// This is a workaround for envinfo's Android SDK check not working on
// Windows. This can be removed when envinfo fixes it.
// See the PR: https://github.com/tabrindle/envinfo/pull/119
if (sdks === 'Not Found' && process.platform !== 'darwin') {
try {
const {stdout} = await execa(
process.env.ANDROID_HOME
? `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`
: 'sdkmanager',
['--list'],
);

const matches = [];
const regex = /build-tools;([\d|.]+)[\S\s]/g;
let match = null;
while ((match = regex.exec(stdout)) !== null) {
matches.push(match[1]);
}
if (matches.length > 0) {
sdks = {
'Build Tools': matches,
};
}
} catch {}
}

return {
needsToBeFixed:
(sdks === 'Not Found' && installMessage) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make 'Not Found' a constant or make sdks undefined instead?

doesSoftwareNeedToBeFixed({
version: sdks['Build Tools'][0],
versionRange: versionRanges.ANDROID_NDK,
}),
};
},
runAutomaticFix: async ({loader, environmentInfo}) => {
const version = environmentInfo.SDKs['Android SDK'][0];
const isNDKInstalled = version !== 'Not Found';
Expand All @@ -19,15 +56,13 @@ export default {

if (isNDKInstalled) {
return logManualInstallation({
message: `Read more about how to update Android SDK at ${chalk.dim(
'https://developer.android.com/studio',
)}`,
message: installMessage,
});
}

return logManualInstallation({
healthcheck: 'Android SDK',
url: 'https://developer.android.com/studio',
url: 'https://facebook.github.io/react-native/docs/getting-started',
});
},
};
7 changes: 6 additions & 1 deletion packages/cli/src/commands/doctor/healthchecks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export const HEALTHCHECK_TYPES = {
export const getHealthchecks = ({contributor}) => ({
common: {
label: 'Common',
healthchecks: [nodeJS, yarn, npm, watchman],
healthchecks: [
nodeJS,
yarn,
npm,
...(process.platform === 'darwin' ? [watchman] : []),
],
},
android: {
label: 'Android',
Expand Down