33

Is there a way when using Cordova CLI to select a particular emulated device from the Android Device Manager (AVD)?

I am working on a tablet app and a smartphone app at the same time and need to switch to different types of emulators because of the different form factors and screen resolutions?

I know it's not a particular coding question but perhaps there is some Cordova code I can run in terminal to make the emulation more specific rather than:

cordova emulate android

Which seems to pick the first emulator off the stack.

Keith
  • 20,636
  • 11
  • 84
  • 125
Ryan Coolwebs
  • 1,611
  • 5
  • 22
  • 44

4 Answers4

63

Use the target parameter like this:

cordova emulate --target=emulator-5554 android

To get the device name of your emulator ("emulator-5554" in this example), run /platforms/android/cordova/lib/list-started-emulators.bat

Keith
  • 20,636
  • 11
  • 84
  • 125
  • Thanks Keith. Your answer looks promising but I can't seem to run the bat file in MACOSX. Is there a way to do this? I don't suppose I could get the specific device name from the AVD? – Ryan Coolwebs May 22 '14 at 01:42
  • 3
    You ripper! Got the name from the AVD Manager. Not ready for batch files :| Now if only the emulator worked faster. Genymotion a better option? – Ryan Coolwebs May 22 '14 at 04:31
  • Ahh yes the batch file only works for Windows. I think it's the only way to get the device name on Windows because I can't seem to find it via AVD Manager. Too bad, I'd prefer not to use batch files too! – Keith May 22 '14 at 13:26
  • I don't know enough to help you with the emulator performance but maybe [this](http://stackoverflow.com/questions/7946345/android-emulator-laggy-on-mac) will help. – Keith May 22 '14 at 13:28
  • On OSX. Just call `android list avd` from the command line. Found this by calling `android --help` – Jaybeecave May 27 '15 at 10:01
  • 4
    It should be noted, that `emulator-5554` works for already launched AVD (it can be listed with `adb devices` too). However when you want to target un-launched AVD, then the name from AVD Manager can be used. – infografnet Jul 02 '15 at 17:00
  • @RyanCoolwebs how long did your `cordova emulate` command end up requiring? My command prompt is currently hanging (i.e. just waiting!) after running: `cordova emulate --target=emulator-5554 amazon-fireos`. The `exec`'ed command showing in STDOUT is: `exec: adb -s emulator-5554 install -r "/Users/mec/Sites/iom/MTapp/platforms/amazon-fireos/out/path-to-apk.apk"` – mecampbellsoup Sep 09 '15 at 17:05
  • @mecampbellsoup, I never usually had to wait that long but I was only emulating for a handful of Android devices and iOS. Maybe 5 min max? Sounds like yours is not working properly. Is there any other dependencies that might be holding it up? – Ryan Coolwebs Sep 14 '15 at 04:09
  • @infografnet it works, as long as you swap spaces with "_". e.g `Pixel API 25` becomes `Pixel_API_25` – ciaoben Aug 29 '17 at 16:05
9

If you run the following command you will get a list of all available devices:

cordova run android --list

enter image description here

Next you can emulate your app by running:

cordova run android --target="<Device_Name>"
kristofvdj88
  • 855
  • 8
  • 12
4

For me:

If you use OSX, you can open shell in /platforms/android/cordova/lib/ as stated, and write the next command:

./list-emulator-images

after you've gotten the emulator image name,

cordova emulate android --target="the name"
Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
0

*Moderators rejected my edit and said I should share as answer so -

On Linux (from your project folder) use the command:

/platforms/android/cordova/lib/list-started-emulators

(Note that there's no .bat in the command), then look for the console output e.g. emulator-5554. Then as above run:

cordova emulate --target=emulator-5554 android
Kelton Temby
  • 825
  • 10
  • 20