9

As pointed in How to create Android Virtual Device with command line and avdmanager? one can in principle create AVD from command line. Though it is not straightforward. Following the docs, there should be an option -t that specifies what particular device to emulate by specifying targetId.

Unfortunately, as of version 25.3.1 avdmanager does not recognize option -t. There is an option --tag but it does not seem to be a -t equivalent, since it does not recognise the provided targetId (taken from the list).

How can I specify what device to emulate?

Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
cur4so
  • 1,750
  • 4
  • 20
  • 28
  • Does this answer your question? [How to create Android Virtual Device with command line and avdmanager?](https://stackoverflow.com/questions/42792947/how-to-create-android-virtual-device-with-command-line-and-avdmanager) – Serge Stroobandt Apr 05 '21 at 21:01

4 Answers4

10

For e.g. echo "no" | avdmanager --verbose create avd --force --name x86 --device "4in WVGA (Nexus S)" --package "system-images;android-24;google_apis;x86" --tag "google_apis" --abi "x86"

Where:

Usage:
      avdmanager [global options] create avd [action options]
      Global options:
  -s --silent     : Silent mode, shows errors only.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -h --help       : Help on a specific command.

Action "create avd":
  Creates a new Android Virtual Device.
Options:
  -a --snapshot: Place a snapshots file in the AVD, to enable persistence.
  -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'). [required]
  -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
                 or id.
Sergii Pechenizkyi
  • 22,227
  • 7
  • 60
  • 71
  • `--tag "google_apis"` what does it mean? I want to emulate a device, as for example, a phone Nexus 4 or a tablet Nexus 10. They look ways differently. They should have different associated tags. But how do I know these tags? – cur4so Mar 27 '17 at 20:26
  • tag can be `default|google_apis|android-tv|android-wear` depending on the image which you have downloaded. See list of possible images to download here: http://stackoverflow.com/a/42521077/624706 List of possible device params: `avdmanager list device` – Sergii Pechenizkyi Mar 27 '17 at 20:48
  • 1
    `avdmanager list device` gives you ids, but `--device` is not a meaningful parameter. image is a system, which can be installed on different devices. – cur4so Mar 27 '17 at 21:18
8
cd $ANDROID_HOME/tools/bin
yes | ./sdkmanager emulator
export PATH="${ANDROID_HOME}/emulator:${PATH}"
./sdkmanager "system-images;android-25;google_apis;x86"
yes | ./sdkmanager --licenses
./avdmanager list device
./avdmanager create avd -n test -k "system-images;android-25;google_apis;x86"
cd $ANDROID_HOME/tools
sudo apt-get install cpu-checker
kvm-ok
sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder bridge-utils
./emulator -avd test
NickUnuchek
  • 11,794
  • 12
  • 98
  • 138
5

The avdmanager tool and sdkmanager are provided in the Android SDK Tools package (25.3.0 and higher) and is located in {your_android_sdk_directory}/tools/bin/ in terminal run following commands:

  1. ./sdkmanager list
  2. ./avdmanager list device
  3. ./avdmanager create avd -n pixel -k "system-images;android-26;google_apis;x86_64" -d "17"

pixel is the name i gave to the avd.

"system-images;android-26;google_apis;x86_64" got from ./sdkmanager list in Installed packages

"17" is device id got from ./avdmanager list device

change directory to:

  • cd {your_android_sdk_directory}/emulator

To open emulator run command:

  • ./emulator -avd pixel

Pixel is the name given previously to the avd.

Hope it helps others with the new version.

Kevin Kanyi
  • 51
  • 1
  • 1
1

You can download the Android Emulator using the new sdkmanager command line tool and create AVDs via the new avdmanager command line tool. It is easier to do these tasks with the Android Studio AVD manager.

Jamal Eason
  • 6,260
  • 2
  • 19
  • 15
  • 1
    could you be more specific? – cur4so Mar 23 '17 at 03:59
  • 1
    For example per the sdkmanger page ( https://developer.android.com/studio/command-line/sdkmanager.html ), once you have the command line sdk tools installed (https://developer.android.com/studio/index.html#downloads) , you just type in the following to download the Android Emulator: $ ./sdkmanager "emulator" – Jamal Eason Mar 23 '17 at 09:06
  • @JamalEason in my case `emulator` appeared here - `/usr/local/Caskroom/android-sdk/3859397/tools/emulator`, too sad that it's not under $PATH – user1016265 May 14 '18 at 12:08