42

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
  • 11,418
  • 12
  • 70
  • 97

4 Answers4

51

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,643
  • 3
  • 57
  • 78
Gregriggins36
  • 855
  • 10
  • 19
  • 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
  • 2
    @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
  • 13
    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
21

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
  • 8,776
  • 6
  • 56
  • 93
Guillaume Vincent
  • 11,418
  • 12
  • 70
  • 97
  • 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
10

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 from sdkmanager first

$  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
gobernador
  • 5,471
  • 3
  • 30
  • 51
Xingjiu
  • 101
  • 2
0

Here is my version with Powershell

  • downloads system images
  • sets proper resolution
  • adds hw.keyboard=yes to enables keys from your PC to be sent to the emulator

https://gist.github.com/shalva97/dd5aa1aad691763a87a5d40f172803e2