Guillaume Vincent
Guillaume Vincent

Reputation: 14791

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

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?

Upvotes: 50

Views: 113765

Answers (5)

Jusca Molaiwa
Jusca Molaiwa

Reputation: 1

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!

Upvotes: 0

the_prole
the_prole

Reputation: 8945

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

Upvotes: 0

Xingjiu
Xingjiu

Reputation: 127

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

Upvotes: 11

Guillaume Vincent
Guillaume Vincent

Reputation: 14791

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.

Upvotes: 27

Gregriggins36
Gregriggins36

Reputation: 943

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'

Upvotes: 58

Related Questions