After the Android development environment, the Android emulator is perhaps the most powerful and frequently used tool available to the Android app developer.
The Android emulator is a software tool that simulates how a real Android device behaves. Developers can build and deploy their applications to the emulator and then test and debug their applications, without the need for connecting real Android devices via USB. The benefits are immediately obvious:
- The developers can quickly and easily make code updates and run their code on a virtual device.
- Testers can later test on actually devices for adequate test coverage
This simplifies the hardware requirements for the development team and keeps the developer’s desktop from becoming a nest of USB cables, tablets, smartphones and other Android devices. (This might happen anyway, but at least using an emulator will minimize how often you have to dive into the nest. You might even like that nest of devices and cables. 🙂 )
How Is The Android Emulator Configured?
The Android emulator must be launched with an Android Virtual Device (AVD) configuration, which describes a specific type of device to simulate. You can customize your emulator to mimic a variety of Android devices, both real and imagined. You do this simply by creating different AVDs with the device specifications you desire. AVDs are created and managed using the Android SDK and AVD Manager, which is accessible from within Eclipse (see Figure 1).
Some common AVD configuration details include:
- The Android SDK Target
- The SD Card Details
- Screen Size and Density
- Input Method Specifics (Touch Screens, Trackballs, Keyboards, DPads)
- Camera Features and Specifications
- RAM and Cache Settings
- Other Hardware and Sensor Features
There are numerous settings. For a complete list, see the Android SDK documentation regarding AVDs.
Figure 2 shows the Android emulator, when it is used with different AVDs.
How Do I Launch the Android Emulator?
The Android emulator is part of the tools that ship with the Android SDK. If you are using Eclipse as your development environment and have installed the Android Development Tools (ADT) plug-in, then you’ll find it straightforward to get the emulator up and running. When you’ve gotten your application code compiled and ready to run within Eclipse, simply create a Debug configuration. You can set your application’s debug configuration to target a specific AVD, or choose Manual mode and select an AVD on-the-fly. We prefer the Manual mode so we can always choose between running emulators or several USB connected devices.
When you choose to Debug from within Eclipse, the emulator is started with the AVD you chose, your application is installed (or updated), and you can begin to interact with the emulator and run your application. You can also launch any of the Android tools from the command line.
Tip: The emulator takes time to start up, so it’s a good practice to keep it running on your development machine while you’re working. When you choose to debug from Eclipse, your application will simply be updated immediately without the bother of relaunching the emulator.
How Can I Control and Interact with the Android Emulator?
You can use your mouse and keyboard to interact with the emulator after it’s running. Clicking on the emulator screen simulates finger touches. Your keyboard can be used to send specific emulator commands, or as an input method if the AVD specifies a hardware keyboard. Some of the most common commands used on a regular basis include
- Back [ESC button]
- Call [F3]
- End [F4]
- Volume Up [
- Volume down [
- Switching orientations [
You can customize your emulator experience with startup options. These can be set on the Target tab of your debug and run configurations from within Eclipse. For a complete list of Emulator startup options and keyboard commands, see the Emulator Startup Options and Emulator Keyboard Mapping sections in the SDK documentation.
You can also interact with an emulator from within the DDMS tool or Eclipse perspective (Figure 3). Use the Emulator Control panel to specify telephony status, simulate incoming voice calls and SMS messages, and send location data to the emulator for testing purposes.
What Are the Android Emulator’s Limitations?
The emulator is a useful testing tool, but it does not truly replicate how your users will experience your application on real mobile devices, with real networks, true hardware sensors, accurate representation of performance, and unique input characteristics. The emulator can take you only so far. It’s fantastic for developer testing, automated testing, and testing of device configurations you cannot get your hands on. It falls short when it comes to making or receiving real phone calls and simulating hardware like cameras, sensors and GPS, USB, and Bluetooth. We’ve also found that OpenGL graphics and video are best tested on real devices.
The Android emulator is a powerful tool, when used appropriately. You can safely and easily deploy and test applications from the comfort of your desk, without pesky cords, random USB drivers, etc. That said, the emulator has limitations; it’s not a true device, so it doesn’t provide the completely authentic experience that users actually will have.
About the Authors
|Shane Conder and Lauren Darcey—Contributing Editors, Mobile Development–have coauthored two books on Android development: an in-depth programming book entitled Android Wireless Application Development (ISBN-13: 978-0-321-62709-4) and Sams Teach Yourself Android Application Development in 24 Hours (ISBN-13: 978-0-321-67335-0). When not writing, they spend their time developing mobile software at their company and providing consulting services.|