Creating Android Virtual Devices (AVDs)
Some of you may prefer working with your AVDs from the command-line interface for some reason or other. Maybe you have some awesome scripts that you'd like to write to set up some awesome AVDs. This recipe details how to create AVDs and launches them straight from the command line.
How to do it…
Before you can create your own AVDs, you will need to specify some attributes for it; the most important one being the system image that will be used. To do so, execute the following steps:
- You can find a list of the system images available to you by using the following command:
[path-to-sdk-install]/tools/android list targets
Or use the following command from the Windows terminal:
C:\[path-to-sdk-install]\tools\android list targets
As an example, enter the following into the command prompt:
C:\Users\kmakan\Documents\adt-bundle-windows-x86-20130219\sdk\tools\android list targets
This command will list the system images available on your system. If you'd like more, you'll need to install them via the SDK manager. The pieces of information that you're looking for in this list are the target IDs because you'll need them to identify the system image, which you will need to specify in the next step.
- Create the AVD using the following command:
[path-to-sdk-install]/tools/android create avd –n [name of your new AVD] –t [system image target id]
You will need to decide on a name for the AVD you've just created, which you will specify using the
–n
switch. The system image ID you selected from the previous step must be specified using the–t
switch. If everything goes well, you should have just created a brand new virtual machine. - You can launch your brand new AVD using the following command:
[path-to-sdk-install]/tools/emulator –avd [avd name]
Here,
[avd name]
is the AVD name you decided on in the previous step. If all goes well, your new AVD should start right up.
There's more…
You probably want to know a little more about the commands. Regarding the emulator, it's capable of emulating a device with different configurations.
Emulating a memory card or an external storage
You can specify that your virtual device also emulates some external storage using the –c
options when you create it, as shown in the following command:
android create –avd –n [avd name] –t [image id] –c [size][K|M]
For example, see the following command:
android create –avd –n virtdroid –t 1 –c 128
You will obviously need to supply the size of your new emulated memory card. You also need to specify the unit by specifying either K
for kilobytes or M
for megabytes.
The partition sizes
Another very useful thing that you may want to do is specify how much space you'd like to grant the internal storage partitions. You can do this by using the -partition-size
switch, which you specify when you invoke the emulator as shown in the following command:
emulator –avd [name] –partition-size [size in MBs]
You will also need to supply a size for the partitions. By default, the unit of measurement is megabytes (MBs).
See also
There are many other options that you can make use of when it comes to the emulator. If you're interested in learning more, check out the documents provided in the following links: