How to create Android Virtual Device with command line and avdmanager?

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'

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.


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

Tags:

Android