Skip to content

Commit 9700840

Browse files
Fix debug android --emulator
Fix `tns debug android --emulator`. There were two issues: * With latest changes in master/release branch, when there's no android device detected and user executes `tns debug android --emulator` an error is raised - "Cannot find connected devices...". Fix this by returning true in command's canExecute method when `--emulator` is passed. * When there's no running emulator, CLI tries to start it (android-debug-service, debugOnEmulator method). The emulator is started and after that we try to execute action on the started device. However devicesService (in this case the androidDeviceDiscovery) had not reported yet the started emulator as a new device. So when device's service execute method is called, it checks if there are devices (still thinks there aren't) and tries to start emulator again. The final result is that application starts on the device, but there's no debugger attached. Fix this by forcing android device detection in debugOnEmulator method.
1 parent 90e8be3 commit 9700840

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)