The changing landscape of the Android marketplace creates unique challenges and opportunities, many of which are tied to the individual hardware specifications of devices. Hardware optimization has become a consideration for mindful application development. When testing software across a variety of devices and architectures, virtual devices are the go-to tools for agile development. This article will guide you through building customizable emulators and setting up the appropriate environments for developing applications. Tips and best practices will be offered for creating and porting versatile applications and using the Android SDK's tools and platform components to their full potential.
Overview of Android Virtual Device Emulation
Android runs on a variety of form factor devices with different screen sizes, hardware capabilities, and features. A typical device has a multitude of software (Android API) and hardware capabilities like sensors, GPS, camera, SD card and multi-touch screen with specific dimensions.
The emulator is quite flexible and configurable with different software and hardware configuration options. Developers can customize the emulator using the emulator configuration called Android Virtual Device (AVD). AVD can be thought of as a set of configuration files that specify different Android software and device hardware capabilities. The Android emulator uses these AVD configurations to configure and start the appropriate Android virtual image on the emulator.
As documented on the Android website, a typical AVD configuration has:
- A hardware profile that specifies all the device capabilities (examples: camera, sensors).
- A System image, which will be used by the emulator for this AVD (API level to target, such as Gingerbread or Honeycomb).
- A Data image that acts as the dedicated storage space for user's data, settings, and SD card.
- Other options including emulator skin, the screen dimensions, and SD card size.
Developers are encouraged to target different API levels, screen sizes, and hardware capabilities (such as camera, sensors, and multi-touch devices). The AVD configuration can be used to customize the emulator as needed. Developers can create as many AVDs as desired, each one targeting a different Intel architecture–based Android device: For example, a developer can create an Intel architecture–based Gingerbread AVD with a built-in skin like WVGA800, or a custom one manually specifying the screen resolution to be used.
The Android SDK has supported Intel architecture–based Android emulation since version r12. The SDK integrates this support into all developer tools including the eclipse ADT plugin. Figure 1 is a sample screenshot of the Android emulator for x86 running Gingerbread. The model number is highlighted and shows "Full Android on x86 Emulator."
Figure 1: Android emulator.
For detailed instructions on how to use the emulator, please refer to the Android documentation.
Which Emulator Should You Use
At the time of this writing, there are two emulator images available for Intel architecture (x86): one for Android 2.3.7 (Gingerbread), and one for Android 4.0.4 (Ice Cream Sandwich).
While there are many advantages to developing for the latest Android operating system release, many developers prefer to target Android 2.x, as a majority of Android phones in use today do not yet run Android 4.x or higher (in the US, only 1 in 5 Android phones run ICS or higher at the time of this writing). This percentage will change over time, so it is strongly suggested that you keep market conditions in mind when determining your target operating system. For more Gingerbread-specific operating system information, this article may prove useful. For Ice Cream Sandwich information, use this article.
Why Use an Emulator?
First of all, it's free. The Android SDK and its third-party add-ons cost absolutely nothing and allow developers to emulate devices that they do not own and may not have access to. This is important as not all phones acquire the latest Android OS versions via Over The Air (OTA) updates, and it may not be feasible for developers to purchase every device that is expected to support their software package(s).
- Development and testing. Developers can use the SDK to create several Android Virtual Device (AVD) configurations for development and testing purposes. Each AVD can have varying screen dimensions, SD card sizes, or even versions of the Android SDK (which is useful for testing backward compatibility with prior Android builds).
- Playing with a new build. The emulator allows developers to just have fun with a new build of Android and learn more about it.
Let's walk through the steps required to build and run an emulator image on an x86 build. For simplicity's sake, this article will focus on the Gingerbread emulator, though most of this content will apply to the Ice Cream Sandwich emulator as well.