Managing Virtual Devices >

Managing AVDs from the Command Line

The android tool lets you manage AVDs on the command line. For a complete reference of the command line options that you can use, see the reference for the android tool.

Listing targets

To generate a list of system image targets, use this command:

android list targets

The android tool scans the <sdk>/platforms/ and <sdk>/add-ons/ directories looking for valid system images and then generates the list of targets. Here's an example of the command output:

Available Android targets:
id: 1 or "android-3"
     Name: Android 1.5
     Type: Platform
     API level: 3
     Revision: 4
     Skins: QVGA-L, HVGA-L, HVGA (default), HVGA-P, QVGA-P
id: 2 or "android-4"
     Name: Android 1.6
     Type: Platform
     API level: 4
     Revision: 3
     Skins: QVGA, HVGA (default), WVGA800, WVGA854
id: 3 or "android-7"
     Name: Android 2.1-update1
     Type: Platform
     API level: 7
     Revision: 2
     Skins: QVGA, WQVGA400, HVGA (default), WVGA854, WQVGA432, WVGA800
id: 4 or "android-8"
     Name: Android 2.2
     Type: Platform
     API level: 8
     Revision: 2
     Skins: WQVGA400, QVGA, WVGA854, HVGA (default), WVGA800, WQVGA432
id: 5 or "android-9"
     Name: Android 2.3
     Type: Platform
     API level: 9
     Revision: 1
     Skins: HVGA (default), WVGA800, WQVGA432, QVGA, WVGA854, WQVGA400

Creating AVDs

In addition to creating AVDs with the AVD Manager user interface, you can also create them by passing in command line arguments to the android tool.

Open a terminal window and change to the <sdk>/tools/ directory, if needed.

To create each AVD, you issue the command android create avd, with options that specify a name for the new AVD and the system image you want to run on the emulator when the AVD is invoked. You can specify other options on the command line also, such as the emulated SD card size, the emulator skin, or a custom location for the user data files.

Here's the command-line usage for creating an AVD:

android create avd -n <name> -t <targetID> [-<option> <value>] ... 

You can use any name you want for the AVD, but since you are likely to be creating multiple AVDs, you should choose a name that lets you recognize the general characteristics offered by the AVD. The target ID is an integer assigned by the android tool. The target ID is not derived from the system image name, version, or API Level, or other attribute, so you need to run the android list targets command to list the target ID of each system image. You should do this before you run the android create avd command. See the android

tool documentation for more information on the command line options.

When you've selected the target you want to use and made a note of its ID, use the android create avd command to create the AVD, supplying the target ID as the -t argument. Here's an example that creates an AVD with name "my_android1.5" and target ID "2" (the standard Android 1.5 system image in the list above):

android create avd -n my_android1.5 -t 2

If the target you selected was a standard Android system image ("Type: platform"), the android tool next asks you whether you want to create a custom hardware profile.

Android 1.5 is a basic Android platform.
Do you wish to create a custom hardware profile [no]

If you want to set custom hardware emulation options for the AVD, enter "yes" and set values as needed. If you want to use the default hardware emulation options for the AVD, just press the return key (the default is "no"). The android tool creates the AVD with name and system image mapping you requested, with the options you specified. For more information, see Setting Hardware Emulation Options.

Note: If you are creating an AVD whose target is an SDK add-on, the android tool does not allow you to set hardware emulation options. It assumes that the provider of the add-on has set emulation options appropriately for the device that the add-on is modeling, and so prevents you from resetting the options.

Default location of AVD files

When you create an AVD, the android tool creates a dedicated directory for it on your development computer. The directory contains the AVD configuration file, the user data image and SD card image (if available), and any other files associated with the device. Note that the directory does not contain a system image — instead, the AVD configuration file contains a mapping to the system image, which it loads when the AVD is launched.

The android tool also creates an <AVD_name>.ini file for the AVD at the root of the .android/avd/ directory on your computer. The file specifies the location of the AVD directory and always remains at the root the .android directory.

By default, the android tool creates the AVD directory inside ~/.android/avd/ (on Linux/Mac), C:\Documents and Settings\<user>\.android\ on Windows XP, and C:\Users\<user>\.android\ on Windows 7 and Vista. If you want to use a custom location for the AVD directory, you can do so by using the -p <path> option when you create the AVD:

android create avd -n my_android1.5 -t 2 -p path/to/my/avd

If the .android directory is hosted on a network drive, we recommend using the -p option to place the AVD directory in another location. The AVD's .ini file remains in the .android directory on the network drive, regardless of the location of the AVD directory.

Setting Hardware Emulation Options

When you are creating a new AVD that uses a standard Android system image ("Type: platform"), the android tool lets you set hardware emulation options for virtual device. The table below lists the options available and the default values, as well as the names of properties that store the emulated hardware options in the AVD's configuration file (the config.ini file in the AVD's local directory).

Table 1. Available hardware profile options for AVDs and the default values

Characteristic Description Property
Device ram size The amount of physical RAM on the device, in megabytes. Default value is "96". hw.ramSize
Touch-screen support Whether there is a touch screen or not on the device. Default value is "yes". hw.touchScreen
Trackball support Whether there is a trackball on the device. Default value is "yes". hw.trackBall
Keyboard support Whether the device has a QWERTY keyboard. Default value is "yes". hw.keyboard
DPad support Whether the device has DPad keys. Default value is "yes". hw.dPad
GSM modem support Whether there is a GSM modem in the device. Default value is "yes". hw.gsmModem
Camera support Whether the device has a camera. Default value is "no". hw.camera
Maximum horizontal camera pixels Default value is "640". hw.camera.maxHorizontalPixels
Maximum vertical camera pixels Default value is "480". hw.camera.maxVerticalPixels
GPS support Whether there is a GPS in the device. Default value is "yes". hw.gps
Battery support Whether the device can run on a battery. Default value is "yes". hw.battery
Accelerometer Whether there is an accelerometer in the device. Default value is "yes". hw.accelerometer
Audio recording support Whether the device can record audio. Default value is "yes". hw.audioInput
Audio playback support Whether the device can play audio. Default value is "yes". hw.audioOutput
SD Card support Whether the device supports insertion/removal of virtual SD Cards. Default value is "yes". hw.sdCard
Cache partition support Whether we use a /cache partition on the device. Default value is "yes". disk.cachePartition
Cache partition size Default value is "66MB". disk.cachePartition.size
Abstracted LCD density Sets the generalized density characteristic used by the AVD's screen. Default value is "160". hw.lcd.density
Trackball support Whether there is a trackball present. hw.trackBall

Moving an AVD

If you want to move or rename an AVD, you can do so using this command:

android move avd -n <name> [-<option> <value>] ...

Updating an AVD

If, for any reason, the platform/add-on root folder has its name changed (maybe because the user has installed an update of the platform/add-on) then the AVD will not be able to load the system image that it is mapped to. In this case, the android list targets command will produce this output:

The following Android Virtual Devices could not be loaded: 
Name: foo 
Path: <path>/.android/avd/foo.avd 
Error: Invalid value in image.sysdir. Run 'android update avd -n foo' 

To fix this error, use the android update avd command to recompute the path to the system images.

Deleting an AVD

You can use the android tool to delete an AVD. Here is the command usage:

android delete avd -n <name> 

When you issue the command, the android tool looks for an AVD matching the specified name deletes the AVD's directory and files.

↑ Go to top

← Back to Managing Virtual Devices