The Android tools include an emulator,
a piece of software that pretends to be an Android device. This is very
useful for development—it not only enables you to get started on your
Android development without a device, but also enables you to test
device configurations for devices that you do not own.
The Android emulator can
emulate one or several Android devices. Each configuration you want is
stored in an Android Virtual Device (AVD).
If you do not have the SDK and AVD Manager running, you can run it via the android command from your SDK's tools/ directory, or via Window =>
SDK and AVD Manager from Eclipse. It opens with a screen listing the
AVDs you have available; initially, the list will be empty, as shown in Figure 1.
Click the New button to create a new AVD file. This opens the dialog box shown in Figure 2, where you can configure how this AVD should look work.
You need to provide the following:
A name for the AVD:
Since the name goes into files on your development machine, you are
limited by the file name conventions for your operating system (e.g., no
backslashes on Windows).
The Android version (target) you want the emulator to run:
Choose one of the SDKs you installed via the Target drop-down list.
Note that in addition to "pure" Android environments, you will have
options based on the third-party add-ons you selected. For example, you
probably have some options for setting up AVDs containing the Google
APIs, and you will need such an AVD for testing an application that uses
Google Maps.
Details about the SD card the emulator should emulate:
Since Android devices invariably have some form of external storage,
you probably want to set up an SD card, by supplying a size in the
associated field. However, since a file will be created on your
development machine of whatever size you specify for the card, you
probably do not want to create a 2GB emulated SD card. 32MB is a nice
starting point, though you can go larger if needed.
The "skin" or resolution the emulator should run in:
The skin options you have available depend upon what target you chose.
The skins let you choose a typical Android screen resolution (e.g.,
WVGA800 for 800×480). You can also manually specify a resolution when
you want to test a nonstandard configuration.
You can skip the Hardware
section of the dialog box for now, as changing those settings is usually
only required for advanced configurations.
The resulting dialog box might look something like Figure 3.
Click the Create AVD button, and your AVD stub will be created.
To start the emulator, select
it in the Android Virtual Devices list and click Start. You can skip the
launch options for now and just click Launch. The first time you launch
a new AVD, it will take a long time to start up. The second and
subsequent times you start the AVD, it will come up a bit faster, and
usually you need to start it only once per day (e.g., when you start
development). You do not need to stop and restart the emulator every
time you want to test your application, in most cases.
The emulator will go through a few startup phases, the first of which displays a plain-text ANDROID label, as shown in Figure 4.
The second phase displays a graphical Android logo, as shown in Figure 5.
Finally, the emulator reaches the home screen (the first time you run the AVD; see Figure 6) or the keyguard (see Figure 7).
If you get the keyguard, press
the Menu button or slide the green lock on the screen to the right, to
get to the emulator's home screen.