Skip to content

Instantly share code, notes, and snippets.

@mrk-han
Last active August 29, 2025 02:51
Show Gist options
  • Save mrk-han/66ac1a724456cadf1c93f4218c6060ae to your computer and use it in GitHub Desktop.
Save mrk-han/66ac1a724456cadf1c93f4218c6060ae 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 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"

For an emulator that mimics a Pixel 5 Device with Google APIs:

  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 "x86_64" --profile pixel_5

    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_10 &

About

  • The goal of this gist is to quickly pre-install a range of system images to provide our project teams the ability to run emulators on a range of API levels, from API 19 to API 28.
    • These can be run locally or on the base build agent.
  • We create two sets of emulators here, one set with pixel hardware emulation and one set with default oem emulation.

See: Google Documentation on Start the emulator from the command line for more info

Steps

  1. Run the sdkmanager --install commands.
  2. Run the avdmanager commands.

Extra Steps

  • Add aliases to run the emulators with parameters more easily. Or add these parameters to your build steps in TeamCity.
    • Instead of using emulator @{EMULATOR NAME} to run devices, you can use the aliases if they are added.
  • If you run this locally, you can use the -read-only parameter to run multiple devices at the same time. You can then manually run automation against various APIs for added device coverage during regression.

Step 1 - Install the variant you want with SDKManager.

OREO (8.1) API 27

sdkmanager --install "system-images;android-27;google_apis;x86_64"

PIE (9.0) API 28

sdkmanager --install "system-images;android-28;google_apis;x86_64"

Step 2 - Use AVDMANAGER to create emulators

Pixel Emulator with Google Apis and x86 architecture

echo "no" | avdmanager --verbose create avd --force --name "pixel_9.0" --device "pixel" --package "system-images;android-28;google_apis;x86_64" --tag "google_apis" --abi "x86_64"

Generic Emulator with Google Apis

echo "no" | avdmanager --verbose create avd --force --name "generic_9.0" --package "system-images;android-28;google_apis;x86_64" --tag "google_apis" --abi "x86_64"

Extra Steps - Aliases and notes on resolutions

Aliases to run emulators more optimally

Note: Add this alias to ~/.bashrc or ~/.zshrc, or just run using these parameters for best results. -skin 768x1280 is useful to run default emulators successfully because they have a very low resolution out-of-the-box.

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

Note: Add this alias to ~/.bashrc or ~/.zshrc, or just run using these parameters for results. Pixel emulators should run at default resolution of 1080x1920 by default, but can specify this just in-case with the parameter: -skin 1080x1920

alias pixel_9.0 ='emulator @pixel_9.0 -no-boot-anim -netdelay none -no-snapshot -wipe-data -skin 1080x1920 &'

Note You can run all of the emulators above with a -read-only parameter to run multiple emulators at the same time, but this is an experimental feature right now.

Other

  1. aosp_atd and google_atd system images are only available on x86 and ARM architecture at API level 30.
  2. emulator -list-avds will print list of available devices
  3. avdmanager list , avdmanager list target, avdmanager list devices , avdmanager list avd
-   avdmanager list              : Lists existing targets or virtual devices.
-   avdmanager list avd          : Lists existing Android Virtual Devices.
-   avdmanager list target       : Lists existing targets.
-   avdmanager list device       : Lists existing devices.
@ArjunTejaswi
Copy link

@josevelasdev I too am stuck in the same error, got any solution?

@neilnicoli-mosca
Copy link

neilnicoli-mosca commented Jun 13, 2022

I am having an error with sdkmanager --install, with error

Capture571

@mrk-han
Copy link
Author

mrk-han commented Jun 13, 2022

@neilnicoli-mosca Make sure you're passing in an argument after --install. e.g. sdkmanager --install "system-images;android-29;default;x86"

@neilnicoli-mosca
Copy link

@neilnicoli-mosca Make sure you're passing in an argument after --install. e.g. sdkmanager --install "system-images;android-29;default;x86"

Yup, does this had something to do with the version of sdkmanager? I found another tutorial that doesn't use --install for installing system-images and just sdkmanager "system-images;android-29;default;x86" and when I followed it and remove --install, it is was successful.

@BenceBakos
Copy link

How to create tablet emulator?

@cmoulliard
Copy link

Is it possible to increase the disk size using avdmanager command (or something else) as we can do using the Studio ?

@mrk-han
Copy link
Author

mrk-han commented Oct 4, 2022

@cmoulliard Yes! You can use a custom profile with --device that has more disk size, or you can create an emulator with a flag which sets the disk size of the AVD. Check the options in avdmanager

@mrk-han
Copy link
Author

mrk-han commented Oct 4, 2022

@BenceBakos Check avdmanager list device for a tablet, then specify that when creating

@mrk-han
Copy link
Author

mrk-han commented Oct 5, 2022

10/5/2022 -- Cleaned up gist and tried to add more clarity.

@cmoulliard
Copy link

Yes! You can use a custom profile with --device that has more disk size

The advmanager command shows the different devices but nothing is displayed around the disk size !

./cmdline-tools/latest/bin/avdmanager list
id: 1 or "tv_4k"
    Name: Android TV (4K)
    OEM : Google
    Tag : android-tv
---------
id: 2 or "tv_720p"
    Name: Android TV (720p)
    OEM : Google
    Tag : android-tv
...
...

Do you know why the advmanager part of the SDK list more devices vs advmanager tool installed without the Android Studio ?

@cmoulliard
Copy link

you can create an emulator with a flag which sets the disk size of the AVD. Check the options in avdmanager

How can we do that ?

@mrk-han
Copy link
Author

mrk-han commented Oct 5, 2022

@cmoulliard To verify the disk size you can create them and then check the config.ini which is a pain.

If you type avdmanager create avd --help it will give you the options for avdmanager create avd and the output is:

Action "create avd":
  Creates a new Android Virtual Device.
Options:
  -c --sdcard  : Path to a shared SD card image, or size of a new sdcard for
                 the new AVD.
  -g --tag     : The sys-img tag to use for the AVD. The default is to
                 auto-select if the platform has only one tag for its system
                 images.
  -p --path    : Directory where the new AVD will be created.
  -k --package : Package path of the system image for this AVD (e.g.
                 'system-images;android-19;google_apis;x86').
  -n --name    : Name of the new AVD. [required]
  -f --force   : Forces creation (overwrites an existing AVD)
  -b --abi     : The ABI to use for the AVD. The default is to auto-select the
                 ABI if the platform has only one ABI for its system images.
  -d --device  : The optional device definition to use. Can be a device index

-c, or --sdcard can specify the path or the size of the virtual sdcard I believe!

@cmoulliard
Copy link

If you type avdmanager create avd --help it will give you the options for avdmanager create avd and the output is:

We are on the same page here. Nevertheless the list of the devices showed using the avdmanager within a termonal is different from what I see using Android studio

@cmoulliard
Copy link

To verify the disk size you can create them and then check the config.ini which is a pain.

I fully agree. We can nevertheless define the disk data partition using disk.dataPartition.size=2000M but only within the config.ini file created within the avd folder post execution of avdmanager create dvd and emulator ... runs

Screenshot 2022-10-05 at 18 00 20

I suppose that some additional steps are taking place using the Android studio such as gtruncate - https://android.stackexchange.com/questions/142824/how-do-i-resize-internal-storage-of-an-android-studio-avd-image-thats-stuck-at

@mrk-han
Copy link
Author

mrk-han commented Oct 6, 2022

@cmoulliard Try emulator @Nexus_5X_API_23 -partition-size 2048

image

https://developer.android.com/studio/run/emulator-commandline

@cmoulliard
Copy link

Cool. I was able to create the avd but I cannot launch on macos the emulator

~/Applications/sdk/cmdline-tools/latest/bin/sdkmanager "system-images;android-28;google_apis;x86"
~/Applications/sdk/cmdline-tools/latest/bin/avdmanager -v create avd -n android28 -k "system-images;android-28;google_apis;x86" -d pixel_5

~/Applications/sdk/emulator/emulator -avd android28 -partition-size 2000
INFO    | Android emulator version 31.3.11.0 (build_id 9058569) (CL:N/A)
emulator: INFO: checking ANDROID_HOME for valid sdk root...
emulator: INFO: checking ANDROID_SDK_ROOT for valid sdk root...
emulator: WARN: ANDROID_SDK_ROOT is missing.
emulator: WARN: Cannot find valid sdk root from environment variable ANDROID_HOME nor ANDROID_SDK_ROOT,Try to infer from emulator's path
emulator: INFO: guessed sdk root is /Users/cmoullia/Applications/sdk
emulator: WARN: platforms subdirectory is missing under /Users/cmoullia/Applications/sdk, please install it
emulator: WARN: invalid sdk root /Users/cmoullia/Applications/sdk
emulator: WARN: Cannot find valid sdk root path.
PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

Idea ?

@mrk-han
Copy link
Author

mrk-han commented Oct 6, 2022

@cmoulliard your env looks set up wrong. Can you send me the contents of your zshrc or bash profile? or type echo $ANDROID_HOME for me

@mrk-han
Copy link
Author

mrk-han commented Oct 6, 2022

your sdk looks like it is in your applications folder which is wrong

@cmoulliard
Copy link

cmoulliard commented Oct 6, 2022

type echo $ANDROID_HOME for me

it is empty

$ echo $ANDROID_HOME

@mrk-han
Copy link
Author

mrk-han commented Oct 6, 2022

@cmoulliard You will need to set that in your ~/.zshrc file, or bashrc file. Depending on what your default login shell is.

It’s usually located in $HOME/Library/android/sdk/ - I can send more info in the morning. I think I have an example of mine in the comments in this gist here at the top.

@cmoulliard
Copy link

That fails too if I set ANDROID_HOME

ANDROID_HOME=~/Applications/sdk 
$ANDROID_HOME/emulator/emulator -avd android28 -partition-size 2000
INFO    | Android emulator version 31.3.11.0 (build_id 9058569) (CL:N/A)
emulator: INFO: checking ANDROID_HOME for valid sdk root...
emulator: INFO: checking ANDROID_SDK_ROOT for valid sdk root...
emulator: WARN: ANDROID_SDK_ROOT is missing.
emulator: WARN: Cannot find valid sdk root from environment variable ANDROID_HOME nor ANDROID_SDK_ROOT,Try to infer from emulator's path
emulator: INFO: guessed sdk root is /Users/cmoullia/Applications/sdk
emulator: WARN: platforms subdirectory is missing under /Users/cmoullia/Applications/sdk, please install it
emulator: WARN: invalid sdk root /Users/cmoullia/Applications/sdk
emulator: WARN: Cannot find valid sdk root path.
PANIC: Cannot find AVD system path. Please define ANDROID_SDK_ROOT

@cmoulliard
Copy link

It’s usually located in $HOME/Library/android/sdk/

I'm using the emulator installed under the sdk command line tools folder

ls -la $ANDROID_HOME
total 8
drwxr-xr-x  10 cmoullia  staff  320 Oct  5 19:02 .
drwx------@ 11 cmoullia  staff  352 Oct  5 18:53 ..
drwxr-xr-x   3 cmoullia  staff   96 Oct  5 18:53 cmdline-tools
drwxr-xr-x  20 cmoullia  staff  640 Oct  5 19:00 emulator
drwxr-xr-x   4 cmoullia  staff  128 Oct  5 19:02 licenses
drwxr-xr-x   3 cmoullia  staff   96 Oct  5 18:54 patcher
drwxr-xr-x  18 cmoullia  staff  576 Oct  5 19:00 platform-tools
drwxr-xr-x   3 cmoullia  staff   96 Oct  5 19:02 system-images


ls -la $ANDROID_HOME/cmdline-tools/latest/bin 
total 112
drwxr-xr-x  9 cmoullia  staff   288 Oct  5 18:53 .
drwxr-xr-x  6 cmoullia  staff   192 Oct  5 18:53 ..
-rwxr-xr-x  1 cmoullia  staff  5319 Jan  1  2010 apkanalyzer
-rwxr-xr-x  1 cmoullia  staff  5310 Jan  1  2010 avdmanager
-rwxr-xr-x  1 cmoullia  staff  5278 Jan  1  2010 lint
-rwxr-xr-x  1 cmoullia  staff  5251 Jan  1  2010 profgen
-rwxr-xr-x  1 cmoullia  staff  5251 Jan  1  2010 retrace
-rwxr-xr-x  1 cmoullia  staff  5307 Jan  1  2010 screenshot2
-rwxr-xr-x  1 cmoullia  staff  5317 Jan  1  2010 sdkmanager

@mrk-han
Copy link
Author

mrk-han commented Oct 6, 2022

export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin

@cmoulliard
Copy link

This export will only allow to get the binaries under $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager|sdkmanager but not at all the emulator which is located under $ANDROID_HOME/emulator/emulator !

@cmoulliard
Copy link

There is a special config to be done to use the emulator coming from the cmdline-tools as we can do

export ANDROID_HOME=/Users/$(whoami)/Applications/sdk
cd $ANDROID_HOME/emulator/
./emulator -list-avds
Pixel_6_API_28
Pixel_6_API_33_2
android28

but not

./emulator -avd android28 -partition-size 2000

@cmoulliard
Copy link

Was able to fix it after creating manually the missing folder platforms

mkdir -p $ANDROID_HOME/platforms

./emulator -avd android28 -partition-size 2000
INFO    | Android emulator version 31.3.11.0 (build_id 9058569) (CL:N/A)
emulator: INFO: Found systemPath /Users/cmoullia/Applications/sdk/system-images/android-28/google_apis/x86/
emulator: INFO: Found systemPath /Users/cmoullia/Applications/sdk/system-images/android-28/google_apis/x86/
INFO    | Duplicate loglines will be removed, if you wish to see each indiviudal line launch with the -log-nofilter flag.
INFO    | configAndStartRenderer: setting vsync to 60 hz
WARNING | cannot add library /Users/cmoullia/Applications/sdk/emulator/qemu/darwin-x86_64/lib64/vulkan/libvulkan.dylib: failed
INFO    | added library /Users/cmoullia/Applications/sdk/emulator/lib64/vulkan/libvulkan.dylib
WARNING | *** No gRPC protection active, consider launching with the -grpc-use-jwt flag.***
INFO    | Started GRPC server at 127.0.0.1:8554, security: Local, auth: none
INFO    | Advertising in: /Users/cmoullia/Library/Caches/TemporaryItems/avd/running/pid_3987.ini
INFO    | setDisplayConfigs w 1080 h 2340 dpiX 440 dpiY 440

@moonga-tech
Copy link

why is it taking long installing, any help??

@justinmoon
Copy link

Helped me to just set ANDROID_AVD_HOME manually ...

@avnikolaev
Copy link

avnikolaev commented Apr 10, 2024

Hi, Guys!
I'm facing with issue when try to start emulator with created AVD.
I try to make remote development environment, because of Serverpod couldn't installed to Windows host.
The main question is - Is it really possible to start emulator from remote ssh in VSCode?
If YES - pls. help to solve my issue... I haven't any more idea. :(
Remote system is Ubuntu 23.10.1
image
INFO | Storing crashdata in: /tmp/android-serverpod/emu-crash-35.1.4.db, detection is enabled for process: 100787
INFO | Android emulator version 35.1.4.0 (build_id 11672324) (CL:N/A)
INFO | Found systemPath /home/serverpod/android/sdk/system-images/android-33-ext5/google_apis_playstore/x86_64/
INFO | Storing crashdata in: /tmp/android-serverpod/emu-crash-35.1.4.db, detection is enabled for process: 100787
INFO | Duplicate loglines will be removed, if you wish to see each individual line launch with the -log-nofilter flag.
INFO | Increasing RAM size to 3072MB
INFO | Warning: could not connect to display ((null):0, (null))
INFO | Warning: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin. ((null):0, (null))
INFO | Info: Could not load the Qt platform plugin "xcb" in "/home/serverpod/android/sdk/emulator/lib64/qt/plugins" even though it was found. ((null):0, (null))
INFO | Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb, vnc, offscreen, linuxfb, minimal.
((null):0, (null))
[ERR] Fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
[ERR] Available platform plugins are: xcb, vnc, offscreen, linuxfb, minimal.
[ERR] ((null):0, (null))
[ERR] [100797:100797:20240410,180304.089230:ERROR elf_dynamic_array_reader.h:64] tag not found
[ERR] [100797:100797:20240410,180304.090202:ERROR process_memory_range.cc:75] read out of range
[ERR] [100797:100797:20240410,180304.091959:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[ERR] [100797:100797:20240410,180304.091983:ERROR file_io_posix.cc:144] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
[ERR] [100797:100797:20240410,180304.092941:ERROR process_memory_range.cc:75] read out of range
[ERR] [100797:100797:20240410,180304.092957:ERROR process_memory_range.cc:75] read out of range
[ERR] Aborted (core dumped)

@vral-parmar
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment