Creating a Kindle Fire Android Virtual Device (AVD)

From Techotopia
Revision as of 21:13, 13 December 2011 by Neil (Talk | contribs) (New page: It will be necessary to compile and run an application multiple times during the development process. An Android application for the Kindle Fire may be tested by installing and running it ...)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

It will be necessary to compile and run an application multiple times during the development process. An Android application for the Kindle Fire may be tested by installing and running it on either a physical device or in an Android Virtual Device (AVD) emulator environment. Before an AVD can be used it must first be created and configured to match the specification of the Kindle Fire. The goal of this chapter, therefore, is to work through the steps involved in creating such a virtual device.


Contents


About Android Virtual Devices

AVDs are essentially emulators that allow Android applications to be tested without the necessity to install the application on a physical Android based device. An AVD may be configured to emulate a variety of hardware features including options such as screen size, RAM capacity and the presence or otherwise of features such a camera, GPS navigation support or an accelerometer.

When launched, an AVD will appear as a window containing an emulated Android device environment as illustrated in Figure 3-1:


An Android AVD Emulator running

Figure 3-1


New AVDs are created and managed using the Android Virtual Device Manager which may be used either in command-line mode or with a more user friendly graphical user interface.

Kindle Fire AVD Specifications

In order to provide accurate emulation of a Kindle Fire an AVD will need to be created with the following properties:

  • Target - Android 2.3.3 (API Level 10)
  • Resolution - 600 x 1024
  • Device RAM Size - 512Mb
  • Abstracted LCD density - 169

Creating a Kindle Fire AVD

In order to create a new AVD matching the above Kindle Fire specifications the first step is to launch the AVD Manager. This can be achieved from within the Eclipse environment using the Window -> AVD Manager menu option. Alternatively, the tool may launched from the command-line using the following command:

android avd

Once launched, the tool will appear as outlined in Figure 3-2. Assuming a new Android SDK installation, no AVDs will currently be listed:


The AVD Manager Window

Figure 3-2


Begin the AVD creation process by clicking on the New… button in order to invoke the Create a New Android Virtual Device (AVD) dialog. Within the dialog, perform the following steps to create a Kindle Fire compatible emulator:

1. Enter a descriptive name (for example KindleFire) into the name field. Note that spaces and other special characters are not permitted in the name.

2. Use the Target menu to select the Android 2.3.3 – API Level 10 SDK option.

3. In the Skin section select the Resolution option and enter 600 x 1024.

4. Click on the current Abstracted LCD Density value located in the Hardware section and change it to 169.

5. Click on the Device ram size value and change it to 512.

Figure 3-3 illustrates the dialog with the appropriate settings implemented. Once the configuration settings are complete, click on the Create AVD button.


Creating a Kindle Fire compatible AVD

Figure 3-3


With the AVD created the AVD Manager may now be closed. If future modifications to the AVD are necessary simply re-open the AVD Manager, select the AVD from the list and click on the Edit… button.

Kindle Fire AVD Command-line Creation

As previously discussed, in addition to the graphical user interface it also possible to create a new AVD directly from the command-line. This is achieved using the android tool in conjunction with some command-line options. Once initiated, the tool will prompt for additional information before creating the new AVD.

Assuming that the system has been configured such that the Android SDK tools directory is included in the PATH environment variable a list of available targets for the new AVD may be obtained by issuing the following command in a terminal or command window:

android list targets

The resulting output from the above command will contain a list of Android SDK versions that are available on the system. For example:

Available Android targets:
----------
id: 1 or "android-10"
     Name: Android 2.3.3
     Type: Platform
     API level: 10
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WVGA800 (default), WVGA854
     ABIs : armeabi
----------
id: 2 or "android-14"
     Name: Android 4.0
     Type: Platform
     API level: 14
     Revision: 1
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800
     ABIs : armeabi-v7a
----------

Since the objective is to create an AVD suitable for testing Android applications intended for the Kindle Fire, the correct target in the above example is the one labeled id 1 or “android-10”.

The syntax for AVD creation is as follows:

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

For example, to create a new AVD named KindleFire using the correct target id (in this case 1), the following command may be used:

android create avd -n KindleFire2 -t 1

The tool will subsequently ask whether a custom hardware profile is to be created. Since the specification of the Kindle Fire differs from the default settings for the selected target it is necessary to enter “y” at this point and configure the emulator. When answering subsequent the questions keep in mind the hardware restrictions of the Kindle Fire (for example, no GPS, GSM modem, audio input, SD card, camera or keyboard support). In fact, the only properties that need to be set are hw.ramSize (512), hw.lcd.height (1024), hw.lcd.width (600) and hw.lcd.density (169).

In addition to the creation of new AVDs, a number of other tasks may be performed from the command line. For example, a list of currently available AVDs may be obtained using the list avd command line arguments:

android list avd
Available Android Virtual Devices:
    Name: KindleFire
    Path: /Users/demo/.android/avd/KindleFire.avd
  Target: Android 2.3.3 (API level 10)
     ABI: armeabi
    Skin: 600x1024

Similarly, to delete an existing AVD, simply use the delete option as follows:

android delete avd –name <avd name>

Android Virtual Device Configuration Files

By default, the files associated with an AVD are stored in the .android/avd sub-directory of the user’s home directory, the structure of which is as follows (where <avd name> is replaced by the name assigned to the AVD):

<avd name>.avd/config.ini
<avd name>.avd/userdata.img
<avd name>.ini

The config.ini file contains the device configuration settings specified during the AVD creation process. For example, the config.ini file for a Kindle Fire compatible AVD will read as follows:

hw.lcd.density=169
skin.path=600x1024
skin.name=600x1024
hw.cpu.arch=arm
abi.type=armeabi
vm.heapSize=24
hw.ramSize=512
image.sysdir.1=platforms/android-10/images/

These settings may be changed directly within the configuration file and will be adopted by the AVD when it is next invoked.

The <avd name>.ini file contains a reference to the target Android SDK and the path to the AVD files. Note that a change to the image.sysdir value in the config.ini file will also need to be reflected in the target value of this file.

Moving and Renaming an Android Virtual Device

The current name, or the location of the AVD files may be altered from the command line using the android tool’s move avd argument. For example, to rename an AVD named KindleFire2 to KindleFire3, the following command may be executed:

android move avd -n KindleFire2 -r KindleFire3
AVD 'KindleFire2' moved.

To physically relocate the files associated with the AVD, the following command syntax should be used:

android move avd -n <avd name> -p <path to new location>

For example, to move an AVD from its current file system location to /tmp/KindleFireTest:

android move avd -n KindleFire2 -p /tmp/KindleFireTest

Note that the destination directory must not already exist prior to executing the command to move an AVD.

Summary

A typically application development process follows a cycle of coding, compiling and running in a test environment. Android applications may be tested either on a physical Kindle Fire device or using an Android Virtual Device (AVD) emulator. AVDs are created and managed using the Android AVD Manager tool which may used either as a command line tool or using a graphical user interface. When creating an AVD to simulate the Kindle Fire it is important that the virtual device be configured with a hardware specification that matches the physical device.

Now that we have created and configured an AVD the next step is to create a simple application and run it within the AVD.