How to create AVD from command line using a hardware profile?

2.6k views Asked by At

Currently I've been managing AVDs via the Android Studio UI at Tools > AVD Manager. This works for creating an AVD with a specific hardware profile (that I have in an XML file), but I find that frequently an AVD is breaking somehow. Next to the AVD is a "Repair" option in the UI, and the hardware profile I've added gets removed, causing me to enter it all in again. This is painful and frequent so I'd like to automate it via the command line.

I can create an AVD using a command like avdmanager create avd -n test1 -k "system-images;android-29;google_apis;x86", but it prompts for custom hardware, and if I choose a custom hardware profile it prompts me to enter in each individual property. This is more time-consuming than using the UI.

This source claims "the android tool lets you set hardware emulation options for virtual device", and provides a nice list of properties than can be modified, but no explanation of how these can be set via a command.

Is there some way to set the hardware profile for an AVD from the command line without manually answering prompts?

2

There are 2 answers

0
Tamlyn On

You should be able to use the --device/-d flag.

First get a list of the available device definitions:

$ avdmanager list device

Available devices definitions:
id: 1 or "Galaxy Nexus"
    Name: Galaxy Nexus
    OEM : Google
---------
id: 2 or "desktop_large"
    Name: Large Desktop
    OEM : Google
    Tag : android-desktop
---------
id: 3 or "desktop_medium"
    Name: Medium Desktop
    OEM : Google
    Tag : android-desktop
---------
id: 4 or "Nexus 10"
    Name: Nexus 10
    OEM : Google
---------
[...]

Then use the numeric or string ID when you create your AVD:

$ avdmanager create avd -d "Nexus 10" -n test1 -k "system-images;android-29;google_apis;x86"
0
NIPHIN On

Could you please try modifying the AVD configuration file config.ini for the required AVD that needs to be modified. Copy an existing AVD, make necessaryy changes to hardware profile and use it as base

Ref:

https://developer.android.com/studio/run/managing-avds#copyavd

https://stuff.mit.edu/afs/sipb/project/android/docs/tools/devices/managing-avds-cmdline.html#hardwareopts

https://developer.android.com/studio/run/managing-avds#hardware-profile