@@ -7,9 +7,9 @@ import { UnityEditor } from './unity-editor';
77import {
88 isProcessElevated ,
99 ReadFileContents ,
10- ResolveGlobToPath
10+ ResolveGlobToPath ,
11+ ResolvePathCandidates ,
1112} from './utilities' ;
12- import { satisfies } from 'semver' ;
1313
1414const logger = Logger . instance ;
1515
@@ -86,16 +86,16 @@ async function getJDKPath(editor: UnityEditor): Promise<string> {
8686}
8787
8888async function getSdkManager ( editor : UnityEditor ) : Promise < string > {
89- let globPath : string [ ] = [ ] ;
89+ let globCandidates : string [ ] [ ] = [ ] ;
9090 if ( editor . version . range ( '>=2019.0.0 <2021.0.0' ) ) {
9191 logger . debug ( 'Using sdkmanager bundled with Unity 2019 and 2020' ) ;
9292 switch ( process . platform ) {
9393 case 'darwin' :
9494 case 'linux' :
95- globPath = [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'sdkmanager' ] ;
95+ globCandidates = [ [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'sdkmanager' ] ] ;
9696 break ;
9797 case 'win32' :
98- globPath = [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'sdkmanager.bat' ] ;
98+ globCandidates = [ [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'sdkmanager.bat' ] ] ;
9999 break ;
100100 default :
101101 throw new Error ( `Unsupported platform: ${ process . platform } ` ) ;
@@ -105,10 +105,10 @@ async function getSdkManager(editor: UnityEditor): Promise<string> {
105105 switch ( process . platform ) {
106106 case 'darwin' :
107107 case 'linux' :
108- globPath = [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'cmdline-tools' , '**' , 'sdkmanager' ] ;
108+ globCandidates = [ [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'cmdline-tools' , '**' , 'sdkmanager' ] ] ;
109109 break ;
110110 case 'win32' :
111- globPath = [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'cmdline-tools' , '**' , 'sdkmanager.bat' ] ;
111+ globCandidates = [ [ editor . editorRootPath , '**' , 'AndroidPlayer' , '**' , 'cmdline-tools' , '**' , 'sdkmanager.bat' ] ] ;
112112 break ;
113113 default :
114114 throw new Error ( `Unsupported platform: ${ process . platform } ` ) ;
@@ -121,23 +121,32 @@ async function getSdkManager(editor: UnityEditor): Promise<string> {
121121 throw new Error ( 'Android installation not found: No system ANDROID_SDK_ROOT or ANDROID_HOME defined' ) ;
122122 }
123123
124+ const sdkManagerBinary = process . platform === 'win32' ? 'sdkmanager.bat' : 'sdkmanager' ;
124125 switch ( process . platform ) {
125126 case 'darwin' :
126127 case 'linux' :
127- globPath = [ systemSdkPath , 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager' ] ;
128- break ;
129128 case 'win32' :
130- globPath = [ systemSdkPath , 'cmdline-tools' , 'latest' , 'bin' , 'sdkmanager.bat' ] ;
129+ globCandidates = [
130+ [ systemSdkPath , 'cmdline-tools' , 'latest' , 'bin' , sdkManagerBinary ] ,
131+ [ systemSdkPath , 'cmdline-tools' , '**' , 'bin' , sdkManagerBinary ] ,
132+ [ systemSdkPath , 'tools' , 'bin' , sdkManagerBinary ]
133+ ] ;
131134 break ;
132135 default :
133136 throw new Error ( `Unsupported platform: ${ process . platform } ` ) ;
134137 }
135138 }
136139
137- const sdkmanagerPath = await ResolveGlobToPath ( globPath ) ;
140+ const sdkmanagerPath = await ResolvePathCandidates ( globCandidates ) ;
138141
139142 if ( ! sdkmanagerPath ) {
140- throw new Error ( `Failed to resolve sdkmanager in ${ globPath } ` ) ;
143+ const normalizedCandidates = globCandidates . map ( candidate => path . join ( ...candidate ) . split ( path . sep ) . join ( '/' ) ) ;
144+ if ( normalizedCandidates . length > 0 ) {
145+ logger . ci ( `sdkmanager glob candidates:\n${ normalizedCandidates . map ( candidate => ` > ${ candidate } ` ) . join ( '\n' ) } ` ) ;
146+ } else {
147+ logger . ci ( 'sdkmanager glob candidates:\n > <none>' ) ;
148+ }
149+ throw new Error ( 'Failed to resolve sdkmanager in expected locations' ) ;
141150 }
142151
143152 await fs . promises . access ( sdkmanagerPath , fs . constants . R_OK ) ;
0 commit comments