Create an Android Virtual Device

Now that we have the Android SDK and PhoneGap installed, (and our PATH variable updated), we need to create a device emulator that will allow us to test our code in a simulated environment.

1. To see a list of available targets, enter the following:

android list targets

I downloaded all of the SDK platforms, so running this command on my machine lists four options:

jsc-mbp:~ jstark$ android list targets Available Android targets: id: 1 or "android-3" Name: Android 1.5 Type: Platform API level: 3 Revision: 4

Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P id: 2 or "android-4" Name: Android 1.6 Type: Platform API level: 4 Revision: 3

Skins: HVGA (default), QVGA, WVGA800, WVGA854 id: 3 or "android-7"

Name: Android 2.1-update1 Type: Platform API level: 7 Revision: 2

Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854 id: 4 or "android-8" Name: Android 2.2 Type: Platform API level: 8 Revision: 1

Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854

Take note of the ID string listed in the output for Android 2.1 (i.e., android-7). This SDK is the most widely deployed platform at the time of this writing.

2. Enter the following command to create your AVD:

android create avd -n mySim -t android-7

Here we're telling Android to create a virtual device (avd) with the name (-n) "mySim" that targets (-t) the android-7 platform.

When asked if you want to configure custom options, just type no and press Enter. The process should only take a few seconds and when it's complete, the emulator is installed.

3. To launch the emulator, enter the following command: emulator -avd mySim

Here we're using the emulator command to launch the Android Virtual Device that we just created. The -avd flag is followed by the name you chose when creating your AVD in the previous step.

Wait while the emulator initializes and eventually displays the phone's home screen (Figure 7-6). The first launch can take a minute or two, so be patient.

Figure 7-6. The Android Virtual Device (AVD) allows you to test and debug your app without using an actual phone
0 0

Post a comment