@@ -16,6 +16,7 @@ export class AndroidVirtualDeviceService implements Mobile.IAndroidVirtualDevice
16
16
private $emulatorHelper : Mobile . IEmulatorHelper ,
17
17
private $fs : IFileSystem ,
18
18
private $hostInfo : IHostInfo ,
19
+ private $sysInfo : ISysInfo ,
19
20
private $logger : ILogger ) {
20
21
this . androidHome = process . env . ANDROID_HOME ;
21
22
}
@@ -152,8 +153,12 @@ export class AndroidVirtualDeviceService implements Mobile.IAndroidVirtualDevice
152
153
let result : ISpawnResult = null ;
153
154
let devices : Mobile . IDeviceInfo [ ] = [ ] ;
154
155
let errors : string [ ] = [ ] ;
156
+ const canExecuteAvdManagerCommand = await this . canExecuteAvdManagerCommand ( ) ;
157
+ if ( ! canExecuteAvdManagerCommand ) {
158
+ errors = [ "Unable to execute avdmanager, ensure JAVA_HOME is set and points to correct directory" ] ;
159
+ }
155
160
156
- if ( this . pathToAvdManagerExecutable && this . $fs . exists ( this . pathToAvdManagerExecutable ) ) {
161
+ if ( canExecuteAvdManagerCommand ) {
157
162
result = await this . $childProcess . trySpawnFromCloseEvent ( this . pathToAvdManagerExecutable , [ "list" , "avds" ] ) ;
158
163
} else if ( this . pathToAndroidExecutable && this . $fs . exists ( this . pathToAndroidExecutable ) ) {
159
164
result = await this . $childProcess . trySpawnFromCloseEvent ( this . pathToAndroidExecutable , [ "list" , "avd" ] ) ;
@@ -169,6 +174,22 @@ export class AndroidVirtualDeviceService implements Mobile.IAndroidVirtualDevice
169
174
return { devices, errors } ;
170
175
}
171
176
177
+ @cache ( )
178
+ private async canExecuteAvdManagerCommand ( ) : Promise < boolean > {
179
+ let canExecute = false ;
180
+ if ( this . pathToAvdManagerExecutable && this . $fs . exists ( this . pathToAvdManagerExecutable ) ) {
181
+ if ( process . env . JAVA_HOME ) {
182
+ // In case JAVA_HOME is set, but it points to incorrect directory (i.e. there's no java in $JAVA_HOME/bin/java), avdmanager will fail
183
+ // no matter if you have correct java in PATH.
184
+ canExecute = ! ! ( await this . $sysInfo . getJavaVersionFromJavaHome ( ) ) ;
185
+ } else {
186
+ canExecute = ! ! ( await this . $sysInfo . getJavaVersionFromPath ( ) ) ;
187
+ }
188
+ }
189
+
190
+ return canExecute ;
191
+ }
192
+
172
193
private async getRunningEmulatorData ( runningEmulatorId : string , availableEmulators : Mobile . IDeviceInfo [ ] ) : Promise < Mobile . IDeviceInfo > {
173
194
const imageIdentifier = await this . getRunningEmulatorImageIdentifier ( runningEmulatorId ) ;
174
195
const runningEmulator = this . $emulatorHelper . getEmulatorByImageIdentifier ( imageIdentifier , availableEmulators ) ;
0 commit comments