Creating an Android Virtual Device

To run an application in the emulator requires a bit of setup with the new ADT plug-in. Specifically, before you can run an application in the emulator, you'll have to create at least one Android Virtual Device (AVD). An AVD represents a device configuration. For example, you could have an AVD representing an Android device running version 1.5 of the SDK with a 32MB SD card. The idea is that you create AVDs you are going to support and then point the emulator to one of those AVDs when developing and testing your application. As you'll see shortly, specifying (and changing) which AVD to use is very easy and makes testing with various configurations a snap. Note that the current version (0.9.1) of the ADT plug-in does not provide a UI for you to create an AVD, so you'll have to create it using the command line.

To create an AVD, you'll use a batch file named android.bat under the tools directory (c:\Android1.5_SDK\tools\). android.bat allows you to create a new AVD and manage existing AVDs. For example, you can view existing AVDs, move AVDs, and so on. You can see the options available for using android.bat by running android -help. For now, let's just create an AVD. The first step is to create a folder where the AVD image will be stored, so create a folder at c:\avd\. The next step is to run the android.bat file to create the AVD:

android create avd -n DefaultAVD -t 2 -c 32M -p C:\AVD\DefaultAVD\

The parameters passed to the batch file are listed in Table 12-1.

Table 12-1. Parameters Passed to the android.bat Tool

Argument/Command Description create avd Tells the tool to create an AVD.

n The name of the AVD.

t The target runtime. Use 1 to specify Android 1.1 and 2 to specify Android 1.5.

c Size of the SD card.

p The path to the generated AVD.

Executing the preceding command will generate an AVD; you should see output similar to what's shown in Figure 12-8. Note that when you run the create avd command, you are asked if you want to create a custom hardware profile. Answer "no" to this question for now.

C:\WINDOWS\system32\cmd.exe

C:SAndroidl.5_SDKStools>android create aud -n DefaultAUD -t 2 -c 32M -p C:\AUD\D efaultflUDS

Android 1.5 is a basic Android platform.

Do ynu wish to create a custom hardware profile [no]

Created HUD 'DefaultAUD' based on Android 1.5

C:SAndroidl.5_SDKStools>

Figure 12-8. Creating an AVD yields this android.bat output.

With that, you have what you need to run an Android application in an emulator. Go back to Eclipse now so you can run the example application you created earlier. Select the Run menu, followed by the Run Configurations... option. In the "Run Configurations" window, select Android Application > HelloAndroid1.5 on the left side of the screen. Leave the defaults in the "Android" tab and then choose the "Target" tab. As shown in Figure 12-9, you can now select the AVD you want to use. Because we only have one AVD, set the "Device Target Selection Mode" to Automatic and then choose DefaultAVD from the list of AVDs. To the run the application in the emulator, click the Run button.

Figure 12-9. Setting the preferred AVD for the emulator

Now you are ready to begin developing with the Android 1.5 SDK. In the sections that follow, we are going to introduce some of the new functionality that is packaged with Android 1.5. We will begin by showing you how to use the new video-capture functionality.

0 0

Post a comment