diff --git a/lib/commands/debug.ts b/lib/commands/debug.ts index 7e0237221d..8a2e7ac6b6 100644 --- a/lib/commands/debug.ts +++ b/lib/commands/debug.ts @@ -16,6 +16,10 @@ export class DebugPlatformCommand implements ICommand { canExecute(args: string[]): IFuture { return ((): boolean => { this.$devicesService.initialize({ platform: this.debugService.platform, deviceId: this.$options.device }).wait(); + if(this.$options.emulator) { + return true; + } + if(this.$devicesService.deviceCount === 0) { this.$errors.failWithoutHelp("No devices detected. Connect a device and try again."); } else if (this.$devicesService.deviceCount > 1) { @@ -34,16 +38,6 @@ export class DebugIOSCommand extends DebugPlatformCommand { $options: IOptions) { super($iOSDebugService, $devicesService, $errors, $options); } - - canExecute(args: string[]): IFuture { - return ((): boolean => { - if(this.$options.emulator) { - return true; - } - - return super.canExecute(args).wait(); - }).future()(); - } } $injector.registerCommand("debug|ios", DebugIOSCommand); @@ -54,9 +48,5 @@ export class DebugAndroidCommand extends DebugPlatformCommand { $options: IOptions) { super($androidDebugService, $devicesService, $errors, $options); } - - canExecute(args: string[]): IFuture { - return super.canExecute(args); - } } $injector.registerCommand("debug|android", DebugAndroidCommand); diff --git a/lib/services/android-debug-service.ts b/lib/services/android-debug-service.ts index 931a8b5df1..e708819e6c 100644 --- a/lib/services/android-debug-service.ts +++ b/lib/services/android-debug-service.ts @@ -20,7 +20,8 @@ class AndroidDebugService implements IDebugService { private $hostInfo: IHostInfo, private $errors: IErrors, private $opener: IOpener, - private $config: IConfiguration) { } + private $config: IConfiguration, + private $androidDeviceDiscovery: Mobile.IDeviceDiscovery) { } public get platform() { return "android"; } @@ -41,6 +42,10 @@ class AndroidDebugService implements IDebugService { private debugOnEmulator(): IFuture { return (() => { this.$platformService.deployOnEmulator(this.platform).wait(); + // Assure we've detected the emulator as device + // For example in case deployOnEmulator had stated new emulator instance + // we need some time to detect it. Let's force detection. + this.$androidDeviceDiscovery.startLookingForDevices().wait(); this.debugOnDevice().wait(); }).future()(); }