7

I'm creating an Android emulator for Espresso testing from a terminal via this command:

./avdmanager create avd -n TestEmulator1 -k "system-images;android-25;google_apis;x86_64" -c 2000M --tag "google_apis" --device "Nexus 5X"

However when I run the emulator, the resolution is really off

enter image description here

When I check it in the AVD Manager from Android Studio, it looks like the settings are correct. Is there something missing from my command that's causing this issue? It causes all of my tests to fail when run. Thanks!

Paul Ruiz
  • 2,396
  • 3
  • 27
  • 47
  • Looks like adding a skin fixed it, though this can't be done in the command line right now https://issuetracker.google.com/issues/37137534 Best bet is creating the emulator and editing the hardware.ini file. – Paul Ruiz Apr 25 '17 at 15:52

4 Answers4

7

Add the skin resolution you need like this:

./avdmanager create avd -n TestEmulator1 -k "system-images;android-25;google_apis;x86_64" -c 2000M --tag "google_apis" --device "Nexus 5X"

./emulator -avd TestEmulator1 -no-window -skin 768x1280 &

Or try if something like this (-s "768x1280") still works with the new avdmanager:

android create avd --force -n nexus4-emulator -t "Google Inc.:Google APIs:"$EMULATOR_VERSION --abi $ANDROID_ABI -s "768x1280" --device "Nexus 4" -c 128M

Further information about emulators with a decent size here.

albodelu
  • 7,931
  • 7
  • 41
  • 84
  • Is the `avdmanager` command a required part of this answer? Also the `android` command is deprecated now. Not sure when that happened, but that's what my Android SDK Tools 26.0.1 installation tells me. – feuGene Jan 18 '18 at 18:25
  • What does --device argument do? It is not in the avdmanager docs... – Scorb Feb 06 '20 at 02:01
4

-skin option is deprecated now.

Try using hw.lcd.width, hw.lcd.height, and hw.lcd.depth to set resolution of the screen inside avd/<avd_name>/config.ini. Works for me.

Supported options are listed here: https://android.googlesource.com/platform/external/qemu/+/refs/heads/master/android/avd/hardware-properties.ini

2

I experienced this problem, and passing the desired resolution to emulator via the -skin "1440x2560" command-line argument is what worked for me.

I personally was trying to start a "Pixel XL" virtual device. I had hoped that the Android SDK could "just know" what resolution that device should run at, but apparently not. So I googled what resolution that device is supposed to have, and passed it in via -skin, and now I'm satisfied (enough).

feuGene
  • 3,931
  • 2
  • 33
  • 46
1

-d seems to fix this

-d --device : The optional device definition to use. Can be a device index or id.

example:

.\avdmanager.bat create avd -n "API-24-Nougat-7.0" -k "system-images;android-27;google_apis_playstore;x86" -d 8

d 8 from .\avdmanager.bat list is Nexus 5, so the resolution becomes 1080x1920

George Shalvashvili
  • 1,263
  • 13
  • 21