@@ -2,15 +2,52 @@ import chalk from 'chalk';
22import { logManualInstallation } from './common' ;
33import versionRanges from '../versionRanges' ;
44import { doesSoftwareNeedToBeFixed } from '../checkInstallation' ;
5+ import execa from 'execa' ;
6+
7+ const installMessage = `Read more about how to update Android SDK at ${ chalk . dim (
8+ 'https://developer.android.com/studio' ,
9+ ) } `;
510
611export default {
712 label : 'Android SDK' ,
8- getDiagnosticsAsync : async ( { SDKs} ) => ( {
9- needsToBeFixed : doesSoftwareNeedToBeFixed ( {
10- version : SDKs [ 'Android SDK' ] [ 'Build Tools' ] [ 0 ] ,
11- versionRange : versionRanges . ANDROID_NDK ,
12- } ) ,
13- } ) ,
13+ getDiagnosticsAsync : async ( { SDKs} ) => {
14+ let sdks = SDKs [ 'Android SDK' ] ;
15+
16+ // This is a workaround for envinfo's Android SDK check not working on
17+ // Windows. This can be removed when envinfo fixes it.
18+ // See the PR: https://github.com/tabrindle/envinfo/pull/119
19+ if ( sdks === 'Not Found' && process . platform !== 'darwin' ) {
20+ try {
21+ const { stdout} = await execa (
22+ process . env . ANDROID_HOME
23+ ? `${ process . env . ANDROID_HOME } /tools/bin/sdkmanager`
24+ : 'sdkmanager' ,
25+ [ '--list' ] ,
26+ ) ;
27+
28+ const matches = [ ] ;
29+ const regex = / b u i l d - t o o l s ; ( [ \d | . ] + ) [ \S \s ] / g;
30+ let match = null ;
31+ while ( ( match = regex . exec ( stdout ) ) !== null ) {
32+ matches . push ( match [ 1 ] ) ;
33+ }
34+ if ( matches . length > 0 ) {
35+ sdks = {
36+ 'Build Tools' : matches ,
37+ } ;
38+ }
39+ } catch { }
40+ }
41+
42+ return {
43+ needsToBeFixed :
44+ ( sdks === 'Not Found' && installMessage ) ||
45+ doesSoftwareNeedToBeFixed ( {
46+ version : sdks [ 'Build Tools' ] [ 0 ] ,
47+ versionRange : versionRanges . ANDROID_NDK ,
48+ } ) ,
49+ } ;
50+ } ,
1451 runAutomaticFix : async ( { loader, environmentInfo} ) => {
1552 const version = environmentInfo . SDKs [ 'Android SDK' ] [ 0 ] ;
1653 const isNDKInstalled = version !== 'Not Found' ;
@@ -19,15 +56,13 @@ export default {
1956
2057 if ( isNDKInstalled ) {
2158 return logManualInstallation ( {
22- message : `Read more about how to update Android SDK at ${ chalk . dim (
23- 'https://developer.android.com/studio' ,
24- ) } `,
59+ message : installMessage ,
2560 } ) ;
2661 }
2762
2863 return logManualInstallation ( {
2964 healthcheck : 'Android SDK' ,
30- url : 'https://developer.android.com/studio ' ,
65+ url : 'https://facebook.github.io/react-native/docs/getting-started ' ,
3166 } ) ;
3267 } ,
3368} ;
0 commit comments