Skip to content

Commit c89e9b2

Browse files
Merge pull request #1474 from NativeScript/vladimirov/fix-debug-emulator
Fix debug android --emulator
2 parents 90e8be3 + 9700840 commit c89e9b2

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

lib/commands/debug.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export class DebugPlatformCommand implements ICommand {
1616
canExecute(args: string[]): IFuture<boolean> {
1717
return ((): boolean => {
1818
this.$devicesService.initialize({ platform: this.debugService.platform, deviceId: this.$options.device }).wait();
19+
if(this.$options.emulator) {
20+
return true;
21+
}
22+
1923
if(this.$devicesService.deviceCount === 0) {
2024
this.$errors.failWithoutHelp("No devices detected. Connect a device and try again.");
2125
} else if (this.$devicesService.deviceCount > 1) {
@@ -34,16 +38,6 @@ export class DebugIOSCommand extends DebugPlatformCommand {
3438
$options: IOptions) {
3539
super($iOSDebugService, $devicesService, $errors, $options);
3640
}
37-
38-
canExecute(args: string[]): IFuture<boolean> {
39-
return ((): boolean => {
40-
if(this.$options.emulator) {
41-
return true;
42-
}
43-
44-
return super.canExecute(args).wait();
45-
}).future<boolean>()();
46-
}
4741
}
4842
$injector.registerCommand("debug|ios", DebugIOSCommand);
4943

@@ -54,9 +48,5 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
5448
$options: IOptions) {
5549
super($androidDebugService, $devicesService, $errors, $options);
5650
}
57-
58-
canExecute(args: string[]): IFuture<boolean> {
59-
return super.canExecute(args);
60-
}
6151
}
6252
$injector.registerCommand("debug|android", DebugAndroidCommand);

lib/services/android-debug-service.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class AndroidDebugService implements IDebugService {
2020
private $hostInfo: IHostInfo,
2121
private $errors: IErrors,
2222
private $opener: IOpener,
23-
private $config: IConfiguration) { }
23+
private $config: IConfiguration,
24+
private $androidDeviceDiscovery: Mobile.IDeviceDiscovery) { }
2425

2526
public get platform() { return "android"; }
2627

@@ -41,6 +42,10 @@ class AndroidDebugService implements IDebugService {
4142
private debugOnEmulator(): IFuture<void> {
4243
return (() => {
4344
this.$platformService.deployOnEmulator(this.platform).wait();
45+
// Assure we've detected the emulator as device
46+
// For example in case deployOnEmulator had stated new emulator instance
47+
// we need some time to detect it. Let's force detection.
48+
this.$androidDeviceDiscovery.startLookingForDevices().wait();
4449
this.debugOnDevice().wait();
4550
}).future<void>()();
4651
}

0 commit comments

Comments
 (0)