Configuring an AVD
You can test programs directly on an Android device through a USB connection between your development computer and the device. Later we will see how to do that, but for rapid development it is very useful to configure emulators that simulate various actual Android devices on your development computer.
Testing with Android Virtual Devices (AVD) has several advantages:
Of course the proof of the pudding is that it should run on actual devices, and emulators do a fairly good job but not a perfect one of simulating actual devices, so ultimately you want to test on real devices. However, using emulators for initial testing and development can greatly speed up the development cycle because they can simulate a variety of conditions that no single device would exhibit.
To configure a basic Android Virtual Device (AVD)
In the resulting window,
select Virtual Devices in the left panel and click the New button on the right. This launches a new window to configure an AVD, as illustrated in the following figure.
After a while (be patient, it may take a minute or so) this should create a new AVD with the characteristics specified that will appear in the list if Virtual Devices is selected in the left panel, as illustrated in the following figure.
Close the Android SDK and AVD Manager window. You now have a basic AVD to test programs running Android 2.2 or earlier. Later we will configure devices with other characteristics in a similar manner.
| You can also launch the AVD manager from the command line with the command android, and you can configure an AVD directly with a command of the form android create avd -n Simple2.2 -c 1024M, where the -n flag denotes a name for the AVD and the -c flag denotes a size for the SD card. Type android --help at the command line to see the list of available options. (Until recently there was a bug in Eclipse with the Android plugin under Fedora 12 and emulators wouldn't launch from Eclipse. They would launch from the command line with a -no-audio flag. This bug appears to have been fixed in the most recent updates.) |
Since the Google maps API is compatible with but separate from the basic Android API, an emulator that will display mapping information must be configured using both the Android and Google Maps API. An attempt to launch an app including Google Mapping using the Simple2.2 emulator configured earlier without mapping capability will give an error message:
[2010-06-08 11:20:26 - MapTutorial] Uploading MapTutorial.apk onto device 'emulator-5554'
[2010-06-08 11:20:26 - MapTutorial] Installing MapTutorial.apk...
[2010-06-08 11:20:27 - MapTutorial] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2010-06-08 11:20:27 - MapTutorial] Please check logcat output for more details.
[2010-06-08 11:20:28 - MapTutorial] Launch canceled!
The missing shared library in this case corresponds to the Google maps API that the Simple2.2 emulator (emulator-5554 in the logged output) does not know anything about. We can remedy this by configuring a new emulator for Android 2.2 that has access to the mapping API.
After a while (it can take a minute or so), this should create a new AVD with the characteristics specified that will appear in the list of Virtual Devices is selected in the left panel. Close the Android SDK and AVD Manager window. You now have a basic AVD to test programs running Android 2.2 with Google mapping capability.
Once you have an AVD (emulator) running you can use the following keyboard mappings to control it.
| Emulated Device Key | Keyboard Key |
| Home | HOME |
| Menu (left softkey) | F2 or Page-up button |
| Star (right softkey) | Shift-F2 or Page Down |
| Back | ESC |
| Call/dial button | F3 |
| Hangup/end call button | F4 |
| Search | F5 |
| Power button | F7 |
| Audio volume up button | KEYPAD_PLUS, Ctrl-5 |
| Audio volume down button | KEYPAD_MINUS, Ctrl-F6 |
| Camera button | Ctrl-KEYPAD_5, Ctrl-F3 |
| Switch to previous layout orientation (for example, portrait, landscape) | KEYPAD_7, Ctrl-F11 |
| Switch to next layout orientation (for example, portrait, landscape) | KEYPAD_9, Ctrl-F12 |
| Toggle cell networking on/off | F8 |
| Toggle code profiling | F9 (only with -trace startup option) |
| Toggle fullscreen mode | Alt-Enter |
| Toggle trackball mode | F6 |
| Enter trackball mode temporarily (while key is pressed) | Delete |
| DPad left/up/right/down | KEYPAD_4/8/6/2 |
| DPad center click | KEYPAD_5 |
| Onion alpha increase/decrease | KEYPAD_MULTIPLY(*) / KEYPAD_DIVIDE(/) |
*Note:to use keypad keys, you must first disable NumLock on your development computer.
For example, if you disable NumLock on the keypad on your keyboard you can use 7 on the keypad to toggle between portrait and landscape orientation for the emulator.