46

I can not create a device with avdmanager command line:

$ Android/Sdk/tools/bin/avdmanager create avd --name Nexus6P --tag 11 --package 'system-images;android-23;google_apis;x86_64'
Error: Invalid --tag 11 for the selected package.

$ Android/Sdk/tools/bin/avdmanager create avd --name Nexus6P --package 'system-images;android-23;google_apis;x86_64'
Error: Invalid --tag default for the selected package.

$ Android/Sdk/tools/bin/avdmanager list
Available Android Virtual Devices:
Available devices definitions:
...
---------
id: 11 or "Nexus 6P"
    Name: Nexus 6P
    OEM : Google
---------

Any idea?

Guillaume Vincent
  • 13,355
  • 13
  • 76
  • 103

5 Answers5

55

If you don't care about it being a Nexus 6P, you can run

echo no | Android/Sdk/tools/bin/avdmanager create avd --force --name testAVD --abi google_apis/x86_64 --package 'system-images;android-23;google_apis;x86_64'
Randika Vishman
  • 7,983
  • 3
  • 57
  • 80
Gregriggins36
  • 905
  • 10
  • 20
  • 1
    thanks to you, here the cli working: `echo no | Android/Sdk/tools/bin/avdmanager create avd --force --name testAVD --abi google_apis/x86_64 --package 'system-images;android-23;google_apis;x86_64'` Can you edit your post to accept your answer. – Guillaume Vincent Mar 15 '17 at 10:50
  • 3
    @Gregriggins36 and if I do care? – cur4so Mar 23 '17 at 18:15
  • Sorry @cur4so I couldn't figure out a way yet – Gregriggins36 Mar 24 '17 at 14:03
  • 14
    by passing `--device "Nexus 6P"` option to avdmanager (see `avdmanager create avd -h`). But with current 25.3.1 tools it creates hardware profile, but ignores resolution. Pass your resolution when starting emulator `emulator @avd_name ..more params here.. -skin 1440x2560` – Sergii Pechenizkyi Mar 27 '17 at 18:36
  • Why when I run that command the emulator files are created on /var/root/.android/avd/ ? I need to create in ~/.android/avd - how to to that? – Francisco Souza Dec 21 '17 at 12:29
  • 1
    @franzisk_br not sure why. Based on this https://developer.android.com/studio/command-line/avdmanager.html#commands_and_command_options it should create the AVD in `~/.android/avd/`. You can always try to force it by adding `-p ~/.android/avd` to the command – Gregriggins36 Dec 23 '17 at 08:33
  • Regarding @SergiiPechenizkyi answer: with the latest build tools this seams resolved. I've just created a pixel-xl emulator with the right hardware profile and resolution by adding `-d pixel_xl`. Adding `-skin 1440x2560` didn't work on my machine – Delblanco Mar 20 '19 at 09:56
  • this emulator doesn't support home and back buttons for instance – Dorian Nov 30 '20 at 19:31
  • You are missing `--device "Nexus 6P"`... whole command would be : `echo no | avdmanager create avd --force --name testAVD --device "Nexus 6P" --abi google_apis/x86 --package 'system-images;android-23;google_apis;x86'` (or use `x86_x64` arch – Dimitri Kopriwa Nov 16 '22 at 14:06
22

The solution from @Gregriggins36 works. Here the detailed solution I use on Linux (Fedora 27)

List the device definitions available:

~/Android/Sdk/tools/bin/avdmanager list
...
---------
id: 11 or "Nexus 6P"
    Name: Nexus 6P
    OEM : Google
---------
...

create a virtual device based on device definition "Nexus 6P"

~/Android/Sdk/tools/bin/avdmanager create avd --force --name Nexus6P --abi google_apis/x86_64 --package 'system-images;android-23;google_apis;x86_64' --device "Nexus 6P"

list virtual devices available

~/Android/Sdk/tools/bin/avdmanager list avd
Name: Nexus6P
Device: Nexus 6P (Google)
Path: /home/guillaume/.android/avd/Nexus6P.avd
Target: Google APIs (Google Inc.)
        Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86_64

start the emulation of our new virtual device

~/Android/Sdk/tools/emulator -avd Nexus6P -skin 1440x2560

Sadly the online documentation is lagging behind the actual tool. Running with --help reveals all the flags you can use, including -d:

$  avdmanager create avd --help

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
                 or id.

tir38
  • 9,810
  • 10
  • 64
  • 107
Guillaume Vincent
  • 13,355
  • 13
  • 76
  • 103
  • With the latest build tools the `-skin 1440x2560` does not seam to workanymore. However I've just created a pixel-xl emulator with the right hardware profile _and resolution_ by adding `-d pixel_xl`. – Delblanco Mar 20 '19 at 09:57
  • where do i find a list of device named like `Nexus 6P `? – the_prole Nov 18 '19 at 18:02
11

Note; Same as accepted answer, but uses x86 (instead of x86_64).

Here is my command that works on Mac.
Notice:

  1. x86 and x86_64 are different ABIs.
  2. You need to download the system_image using sdkmanager first (manually with GUI).

$  avdmanager create avd --force --name testAVD --abi google_apis/x86 --package 'system-images;android-23;google_apis;x86'

Do you wish to create a custom hardware profile? [no] no

$  avdmanager list avd


Name: testAVD
Path: /Users/xj/.android/avd/testAVD.avd
Target: Google APIs (Google Inc.)
      Based on: Android 6.0 (Marshmallow) Tag/ABI: google_apis/x86
Top-Master
  • 7,611
  • 5
  • 39
  • 71
Xingjiu
  • 127
  • 2
0

I'm using AS Flamingo

Create the AVD via AS

then launch it via the command line

emulator -list-avds emulator -avd Pixel_5_API_29

you need all this in your PATH (Windows)

%USERPROFILE%......;C:\Users\UserName\AppData\Local\Android\Sdk\platform-tools;C:\Users\UserName\AppData\Local\Android\Sdk\emulator;C:\Users\UserName\AppData\Local\Android\Sdk\tools\bin

the_prole
  • 8,275
  • 16
  • 78
  • 163
0

Create AVD (Android Virtual Device) on macOS.

You can use the direct path to the avdmanager executable on your system.

Instead of using just 'avdmanager' in your command, replace it with the full path to the avdmanager executable. For example:

echo "no" |/Users/runner/Library/Android/sdk/cmdline-tools/latest/bin/avdmanager --verbose create avd --force --name "pixel_6_pro" --package "system-images;android-33;google_apis;x86_64" --tag "google_apis" --abi "x86_64" --device "pixel_6_pro"

Make sure to adjust the path based on the actual location of the avdmanager executable on your system. Let me know if you have any further questions!