telerik / mobile-cli-lib

Contains common infrastructure for CLIs - mainly AppBuilder, NativeScript, DDB and Proton.
Apache License 2.0
11 stars 10 forks source link

Expose emulator api #1101

Closed Fatme closed 6 years ago

Fatme commented 6 years ago

This PR deletes all legacy, unneeded and duplicated code that is used for working with iOS and Android emulators.

This PR adds the functionalities below:

This PR exposes emulator api from devicesService. The api consists from the following two methods:

  1. getAvailableEmulators(opts?: {platform?: string}) -> Returns all available and running iOS and Android emulators. The method accepts platform parameter, so the emulators can be filtered by platform. The output from the method is in the following format:
    {
    ios: {
        devices: Mobile.IDeviceInfo[],
        errors: string[]
    },
    android: {
        devices: Mobile.IDeviceInfo[],
        errors: string[]
    }
    }

Each available android emulator (NOTE: not running emulator) has the properties below:

{
   identifier: null,
   displayName: the name of the emulator,
   model: the same as the displayName,
   version: The android version of emulator,
   vendor: can be Avd or Genymotion,
   status: not running,
   errorHelp: additional information for errors that prevents working with this device,
   isTablet: false,
   type: Emulator,
   imageIdentifier: for genymotion emulators is the id of virtual machine and for avd is the name of .ini file
}

Each running android emulator has the properties below:

{
   identifier: the emulator identifier,
   displayName: the name of the emulator,
   model: the value of 'ro.product.model' property,
   vendor: the value of 'ro.product.brand' property,
   status: running,
   errorHelp: additional information for errors that prevents working with this device,
   isTablet: when device's 'ro.build.characteristics' property contains "tablet" word or when the 'ro.build.version.release' is 3.x,
   type: Device
   imageIdentifier: for genymotion emulators is the id of virtual machine and for avd is the name of .ini file
}
  1. startEmulator(options) - Starts the specified emulator. The emulator can be specified by imageIdentifier, by name or by emulator object. For android it is possible to pass --timeout option. This option describes the timeout in miliseconds that {N} CLI will wait emulator boot to complete. It might take too long time on some machines to start native android emulator, so this option is useful in such cases.
rosen-vladimirov commented 6 years ago

I've tried this code and I have issues with Genymotion emulators - I do not have paths to Genymotion executables in my PATH, so my expectation was that the emulators will not be available. However, tns devices --available-devices listed my Genymotion emulators.

$ ./bin/tns devices --available-devices

Available emulators
┌─────────────┬──────────┬────────────┬──────────────────────────────────────┐
│ Device Name │ Platform │ Version    │ Device Identifier                    │
│ Nexus 6     │ Android  │ android-24 │ GN6                                  │
│ Nexus 5X    │ Android  │ android-26 │ Nexus_5X_API_26_x86                  │
│ GN5X_API24  │ Android  │ 7.0        │ daa35603-f7ca-46a4-90f5-1116e8cd187d │
└─────────────┴──────────┴────────────┴──────────────────────────────────────┘

Connected devices & emulators
Searching for devices...
iTunes is not installed. Install it on your system and run this command again.
Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again.

I've tried running my app on one of them by passing the name:

$ ../../bin/tns run android --device GN5X_API24
Searching for devices...
Cannot find connected devices.
Emulator start failed with: No emulator image available for emulator 'GN5X_API24'.
To list currently connected devices and verify that the specified identifier exists, run 'tns device'.
To list available emulator images, run 'tns device <Platform> --available-devices'.

After that I've tried with the identifier:

$ ../../bin/tns run android --device  daa35603-f7ca-46a4-90f5-1116e8cd187d
Searching for devices...
Error: spawn player ENOENT
    at _errnoException (util.js:992:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:190:19)
    at onErrorNT (internal/child_process.js:372:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
rosen-vladimirov commented 6 years ago

Also I'm unable to run my normal emulator via its name (not sure if this is supported):

$ ../../bin/tns run android --device "Nexus 5X"
Searching for devices...
Cannot find connected devices.
Emulator start failed with: No emulator image available for emulator 'Nexus 5X'.
To list currently connected devices and verify that the specified identifier exists, run 'tns device'.
To list available emulator images, run 'tns device <Platform> --available-devices'.
rosen-vladimirov commented 6 years ago

When passing the identifier, emulator starts, but CLI hangs and after some time, it fails with error:

Emulator start failed with: Cannot run your app in the native emulator. Increase the timeout of the operation with the --timeout option or try to restart your adb server with 'adb kill-server' command. Alternatively, run the Android Virtual Device manager and increase the allocated RAM for the virtual device.

After that, I execute the same command (note - the emulator is already running) and the operation fails with different error:

$ ../../bin/tns run android --device "Nexus_5X_API_26_x86"
Searching for devices...
Waiting for emulator device initialization...
Could not find device by specified identifier 'Nexus_5X_API_26_x86'. To list currently connected devices and verify that the specified identifier exists, run 'tns device'.

In fact, tns device shows the following:

rosen@DESKTOP-A5EQ3J3 MINGW64 /d/Rosen/Work/nativescript-cli/scratch/app13 (fatme/emulator-api)
$ ../../bin/tns device

Connected devices & emulators
Searching for devices...
iTunes is not installed. Install it on your system and run this command again.
┌───┬────────────────┬──────────┬───────────────────┬──────────┬───────────┐
│ # │ Device Name    │ Platform │ Device Identifier │ Type     │ Status    │
│ 1 │ sdk_gphone_x86 │ Android  │ emulator-5554     │ Emulator │ Connected │
└───┴────────────────┴──────────┴───────────────────┴──────────┴───────────┘

The strange thing is that the name I see for my image is: Nexus 5X API 26 x86, not Nexus_5X_API_26_x86: https://www.screencast.com/t/KjXdsy3jYu Also it looks like it tried to start additional emulator from the same image.