Set Up an Android Virtual Device for App Testing
An Android Virtual Device (AVD) is an emulation of a real Android machine on a PC. It enables testing of Android applications (Apps) on a code development computer.
Why Use Android Virtual Devices?
Android has been around for a few years with devices manufactured to cover various market segments, from mobile and tablet through to watches and TV. There are low cost devices and high specification, high value devices and a wide range of hardware options. For all these reasons there is a large range of Android devices running various operating system (OS) versions. A successful App will run on many of these devices. However, an App developer may not physically own a good range of devices. Testing is done on a small selection of real devices supported by AVDs.
Use AVDs to Test Apps on Different Hardware Profiles
The Android Software Development Kit (SDK) comes with the device emulation tool. Allowing different combinations of AVD hardware and OS versions to be configured. Testing on different AVD combinations reduces issues related to hardware differences in real devices, as used by Android Play customers. Boosting confidence that the App will run reliably when released.
Other reasons for using AVDs for testing:
- Multiple AVD configurations to test an App at different screen sizes.
- Different (emulated) hardware configurations can be used, for example a device with a keyboard or without.
- A compiled App is automatically installed and started when the Run button is pressed in Android Studio.
- Testing on AVDs reduces the amount of physical device testing.
- AVDs can be used alongside a physical device.
- You don't need to handicap you physical device to induce error conditions, e.g. testing on a device with no SD card, just set up an AVD with no SD card.
- An AVD can simulate network events without the costs involved in using a physical device, e.g. simulate phone calls or send an SMS between two AVDs.
- Simulate GPS data from an AVD from different physical locations without moving from your desk.
- When App users report bugs you can try and mimic their hardware configurations using AVDs.
Note: Real Android devices plugged into development machines usually provide better performance for testing Apps than AVDs.
Configuring an AVD
Set up an AVD for App testing using the AVD Manager program. In Android Studio start AVD Manager using the toolbar icon or select Tools in the Android menu.
To create an AVD select the Create Virtual Device button. The Virtual Device Configuration wizard loads:
Choose a common predefined device or generate a new device profile for testing specific hardware configurations. Use the remaining wizard screens to configure the AVD.
Hardware Profile Settings
This table lists the AVD supported properties that can be configured in the wizard for emulated hardware and AVD start up configuration.
|Device Name||String||Name of the device profile|
|Device Type||Phone/Tablet, Wear or TV||Device category|
|Screen Size||Inches||Length of screen diagonal|
|Resolution||X and Y Pixels||Number of width and height pixels|
|Memory||Set RAM in bytes, KB, MB, GB or TB||Amount of physical RAM emulated|
|Hardware Input||Physical Back/Home/Menu buttons and Keyboard||Emulate buttons and keyboard|
|Orientation||Portrait and/or Landscape||Supported orientation states|
|Cameras||Front and/or Back||Supported cameras (emulated or PC cam)|
|Sensors||Accelerometer, Gyroscope, GPS, Proximity||Supported sensors|
|Skin and frame||Select appearance||Skin the emulated device|
|System||Select Android OS version||Android API to emulate|
|Scale||Auto or select dp units to pixels||Customise screen density|
|Performance||Use host GPU or snapshots||Use PC GPU for graphics or save AVD state|
|Network Speed||Full, HSDPA, UMTS, EDGE, GPRS, HSCSD, GSM||Emulate the network speed|
|Network Latency||UMTS, EDGE, GPRS||Emulate the network latency|
|VM Heap||Java heap in bytes, KB, MB, GB or TB||Java Virtual Machine heap|
|Internal Storage||Non-removal space in bytes, KB, MB, GB or TB||Emulated internal memory|
|SD card||Size in bytes, KB, MB, GB or TB or existing file||Emulated removable SD card|
Notes on AVD Settings
- CPU/ABI refers to the target CPU type and the Application Binary Interface (ARM/x86/x86_64). x86 targets perform better than ARM, especially with the Intel Hardware Acceleration Manager (HAXM) installed (by default) on the development computer.
- When naming a new emulated Android device make it descriptive, for example if emulating a device with a version 4.4 operating system and medium resolution screen (HVGA) a name such as And-v4.4-HVGA is better than Android-Device as it is easier to pick out in the list of configured AVDs.
- For the emulated Secure Digital (SD) card the bigger the specified size the bigger the file created on the host computer. Alternatively select an existing SD card image, allowing SD card data sharing amongst different AVDs. On a Windows machine the sdcard.img files will be found in the sub-folders of the avd directory, under the .android directory in the logged on user's profile. (Use the Show on Disk drop down menu option next to the AVD listed in the AVD Manager.)
- Use snapshots if you want the runtime state of the emulated device to persist between sessions. It also reduces the start up time of an AVD for subsequent runs. Though shutdown is longer as the snapshot is written to disk, and host GPU cannot be used to improve AVD graphics performance.
- Use the Wipe Data drop down menu option in the AVD Manager to clear data in the AVD. When the AVD is started the user data file is reset, any user data generated from previous sessions of the selected AVD is lost.
Note on HAXM
The Intel Hardware Accelerated Execution Manager (HAXM) software is installed by default with Android Studio (unless deselected), alternatively see the Intel HAXM home page. HAXM is a hardware assisted virtualization engine (hypervisor). To benefit from HAXM the following is required:
- Check the bios documentation for your PC to see if the motherboard and processor of your development machine supports Intel VT (Virtualization Technology).
- Intel VT must be turned on in the BIOS (see your PCs documentation on how to do that).
- If HAXM has not been installed by Studio download it via the Android SDK using SDK Manager (under Extras) or from Intel. The version of HAXM installed by Studio is out of date. Uninstall it via control panel and install the latest version.
Once the AVD has been defined it will be listed in the AVD Manager window. The AVD is ready to be loaded using the launch (run) button. Once loaded it can be used like any other Android device and driven from the keyboard and mouse of the development computer.
Author:Daniel S. Fowler Published: Updated: