Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Agroil/30d2d643abe11cf9eeffaac95ed1239c to your computer and use it in GitHub Desktop.
Save Agroil/30d2d643abe11cf9eeffaac95ed1239c to your computer and use it in GitHub Desktop.
Installing and creating Emulators with AVDMANAGER (For Continuous Integration Server or Local Use)

Install and Create Emulators using AVDMANAGER and SDKMANAGER

TL;DR

For an emulator that mimics a Pixel 5 Device with Google APIs and ARM architecture (for an M1/M2 Macbook):

  1. List All System Images Available for Download: sdkmanager --list | grep system-images

  2. Download Image: sdkmanager --install "system-images;android-33;google_apis;arm64-v8a"

  3. Create Emulator: echo "no" | avdmanager --verbose create avd --force --name "pixel_5" --package "system-images;android-33;google_apis;arm64-v8a" --tag "google_apis" --abi "arm64-v8a" --device "pixel_5"

Note: To check which devices you can create from the command line, run avdmanager list deviceand pass in the device name as the value of --device, e.g. --device "pixel_5" at the end of the command on step 3.

For generic skin emulator with default apis (without google apis):

  1. List All System Images Available for Download: sdkmanager --list | grep system-images

  2. Download Image: sdkmanager --install "system-images;android-31;default;x86_64"

  3. Create Emulator: echo "no" | avdmanager --verbose create avd --force --name "generic_api31_emulator" --package "system-images;android-31;default;x86_64" --tag "default" --abi "x86_64"

    If you do not use the --device flag, I recommend adding these lines to: ~/.android/avd/generic_10.avd/config.ini or else your emulator will have a very low resolution. 
    Note: Increasing resolution will decrease performance on CI.
    
    skin.name=1080x1920        # proper screen size for emulator
    hw.lcd.density=480
    hw.keyboard=yes            # enables keys from your laptop to be sent to the emulator
    
    If you cannot do this, you can still pass -skin 1080x1920 as an argument when starting the emulator. 
    
    Keep in mind, you can also pass the --device flag and use a device name from the avdmanager list device command which          should also set a default resolution because it will inherit the set of properties of that "device" in the config.ini.
    
  4. Run Emulator: emulator @generic_api31_emulator & or emulator @pixel_5 &

Docs

See: Google Documentation on Start the emulator from the command line for more info See: https://developer.android.com/studio/command-line/avdmanager for more info on AVDManager. See; https://developer.android.com/studio/command-line/sdkmanager for more info on SDKManager.

Aliases

Add aliases to your ~/.zshrc or ~/.bashrc to run the emulators with parameters more easily.

alias generic_api31_emulator='emulator @generic_api31_emulator -no-boot-anim -netdelay none -no-snapshot -wipe-data -skin 768x1280 &'

alias pixel_5 ='emulator @pixel_5 -no-boot-anim -netdelay none -no-snapshot -wipe-data &'

Starting multiple emulators

You can pass the -read-only parameter when starting up an emulator emulator @pixel_5 -read-only to run multiple devices at the same time.

Other

  1. aosp_atd and google_atd system images are only available on x86 and ARM architecture at API level 30. sdkmanager --list | grep atd See also: https://android-developers.googleblog.com/2021/10/whats-new-in-scalable-automated-testing.html
  system-images;android-30;aosp_atd;arm64-v8a                                              | 1            | AOSP ATD ARM 64 v8a System Image
  system-images;android-30;aosp_atd;x86                                                    | 1            | AOSP ATD Intel x86 Atom System Image
  system-images;android-30;google_atd;arm64-v8a                                            | 1            | Google APIs ATD ARM 64 v8a System Image
  system-images;android-30;google_atd;x86                                                  | 1            | Google APIs ATD Intel x86 Atom System Image
  1. avdmanager list device is great to figure out which emulators you can create
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment