Using and Configuring the Android Studio 2 AVD Emulator

From Techotopia
Jump to: navigation, search

The AVD emulator environment bundled with Android Studio 1.x was an uncharacteristically weak point in an otherwise reputable application development environment. Regarded by many developers as slow, inflexible and unreliable, the emulator was long overdue for an overhaul. Fortunately, Android Studio 2 includes an enhanced emulator environment providing significant improvements in terms of configuration flexibility and overall performance. According the Android Studio team at Google, launching an app on the new emulator is now faster than running on a physical Android device. Not only does the emulator contain many new configuration options, these changes can be made in real-time while the application is running.

Before the next chapter explores testing on physical Android devices, this chapter will take some time to provide an overview of the Android Studio 2 AVD emulator and highlight many of the configuration features that are available to customize the environment.


The Emulator Environment

When launched the emulator displays an initial splash screen during the loading process as illustrated in Figure 6-1:

Android studio 2 emulator launch.png

Figure 6-1

Once loaded, the main emulator window appears containing a representation of the chosen device type (in the case of Figure 6-2 this is a Nexus 5 device):

Android studio 2 emualtor running.png

Figure 6-2

Positioned along the right hand edge of the window is the toolbar providing quick access to the emulator controls and configuration options.

The Emulator Toolbar Options

The emulator toolbar (Figure 6-3) provides access to a range of options relating to the appearance and behavior of the emulator environment.

Android studio emulator toolbar diagram.png

Figure 6-3

Each button in the toolbar has associated with it a keyboard accelerator which can be identified either by hovering the mouse pointer over the button and waiting for the tooltip to appear, or via the help option of the extended controls panel.

Though many of the options contained within the toolbar are self-explanatory, each option will be covered for the sake of completeness:

  • Exit / Minimize – The uppermost ‘x’ button in the toolbar exits the emulator session when selected while the ‘-‘ option minimizes the entire window.
  • Power – The Power button simulates the hardware power button on a physical Android device. Clicking and releasing this button will lock the device and turn off the screen. Clicking and holding this button will initiate the device “Power off” request sequence.
  • Volume Up / Down – Two buttons that control the audio volume of playback within the simulator environment.
  • Rotate – Rotates the emulated device between portrait and landscape orientations.
  • Screenshot – Takes a screenshot of the content currently displayed on the device screen. The captured image is stored at the location specified in the Settings screen of the extended controls panel as outlined later in this chapter.
  • Zoom Mode – This button toggles in and out of zoom mode, details of which will be covered later in this chapter.
  • Back – Simulates selection of the standard Android “Back” button. As with the Home and Overview buttons outlined below, the same results can be achieved by selecting the actual buttons on the emulator screen.
  • Home – Simulates selection of the standard Android “Home” button.
  • Overview – Simulates selection of the standard Android “Overview” button which displays the currently running apps on the device.
  • Extended Controls – Displays the extended controls panel, allowing for the configuration of options such as simulated location and telephony activity, battery strength, cellular network type and fingerprint identification.

Working in Zoom Mode

The zoom button located in the emulator toolbar switches in and out of zoom mode. When zoom mode is active the toolbar button is depressed and the mouse pointer appears as a magnifying glass when hovering over the device screen. Clicking the left mouse button will cause the display to zoom in relative to the selected point on the screen, with repeated clicking increasing the zoom level. Conversely, clicking the left mouse button decreases the zoom level. Toggling the zoom button off reverts the display to the default size.

Clicking and dragging while in zoom mode will define a rectangular area into which the view will zoom when the mouse button is released.

While in zoom mode the visible area of the screen may be panned using the horizontal and vertical scrollbars located within the emulator window.

Resizing the Emulator Window

The size of the emulator window (and the corresponding representation of the device) can be changed at any time by clicking and dragging on any of the corners or sides of the window.

Extended Control Options

The extended controls toolbar button displays the panel illustrated in Figure 6 4. By default the location settings will be displayed. Selecting a different category from the left hand panel will display the corresponding group of controls:

Android studio emulator extended controls.png

Figure 6-4


The location controls allow simulated location information to be sent to the emulator in the form of decimal or sexagesimal coordinates. Location information can take the form of a single location, or a sequence of points representing movement of the device, the latter being provided via a file in either GPS Exchange Format (GPX) or Keyhole Markup Language (KML) format.

A single location is transmitted to the emulator when the Send button is clicked. The transmission of GPS data points begins once the “play” button located beneath the data table is selected. The speed at which the GPS data points are fed to the emulator can be controlled using the speed menu adjacent to the play button.


The type of cellular connection being simulated can be changed within the cellular settings screen. Options are available to simulate different network types (CSM, EDGE, HSDPA etc) in addition to a range of voice and data scenarios such as roaming and denied access.


A variety of simulated battery state and charging conditions can be simulated on this panel of the extended controls screen, including battery charge level, battery health and whether the AC charger is currently connected.


The phone extended controls provide two very simple but useful simulations within the emulator. The first option allows for the simulation of an incoming call from a designated phone number. This can be of particular use when testing the way in which an app handles high level interrupts of this nature.

The second option allows the receipt of a text messages to be simulated within the emulator session. As in the real world, these messages appear within the Message app and trigger the standard notifications within the emulator.

Directional Pad

A directional pad (D-Pad) is an additional set of controls either built into an Android device or connected externally (such as a game controller) that provides directional controls (left, right, up, down). The directional pad settings allow D-Pad interaction to be simulated within the emulator.


Many Android devices are now supplied with built-in fingerprint detection hardware. With the introduction of the Android Studio 2 emulator it is now possible to test fingerprint authentication without the need to test apps on a physical device containing a fingerprint sensor. Details on how to configure fingerprint testing within the emulator will be covered in detail later in this chapter.


The settings panel provides a small group of configuration options. Use this panel to choose a darker theme for the toolbar and extended controls panel, specify a file system location into which screenshots are to be saved and choose a different SDK path to be used when running apps within the emulator.


The Help screen contains three sub-panels containing a list of keyboard shortcuts, links to access the emulator online documentation, file bugs and send feedback, and emulator version information.

Drag and Drop Support

An Android application is packaged into an APK file when it is built. When Android Studio built and ran the AndroidSample app created earlier in this book, for example, the application was compiled and packaged into an APK file. That APK file was then transferred to the emulator and launched.

The Android Studio 2 emulator also supports installation of apps by dragging and dropping the corresponding APK file onto the emulator window. To experience this in action, start the emulator, open Settings and select the Apps option. Within the list of installed apps, locate and select the AndroidSample app and, in the app detail screen, uninstall the app from the emulator.

Open the file system navigation tool for your operating system (e.g. Windows Explorer for Windows or Finder for Mac OS X) and navigate to the folder containing the AndroidSample project. Within this folder locate the app/build/outputs/apk subfolder. This folder should contain two APK files named app-debug.apk and app-debug-unaligned.apk. Drag the app-debug.apk file and drop it onto the emulator window. The dialog shown in (Figure 6-5) will subsequently appear as the APK file is installed.

Android studio 2 apk installer.png

Figure 6-5

Once the APK file installation has completed, locate the app on the device and click on it to launch it.

In addition to APK files, any other type of file such as image, video or data files can be installed onto the emulator using this drag and drop feature. Such files are added to the SD card storage area of the emulator where they may subsequently be accessed from within app code.

Configuring Fingerprint Emulation

The emulator allows up to 10 simulated fingerprints to be configured and used to test fingerprint authentication within Android apps. To configure simulated fingerprints begin by launching the emulator, opening the Settings app and selecting the Security option.

Within the Security settings screen, select the Fingerprint option. On the resulting information screen click on the Continue button to proceed to the Fingerprint setup screen. Before fingerprint security can be enabled a backup screen unlocking method (such as a PIN number) must be configured. Click on the Set Up Screen Lock button, choose the PIN option, enter and confirm a suitable PIN number and complete the PIN entry process.

Proceed through the remaining screens until the Settings app requests a fingerprint on the sensor. At this point display the extended controls dialog, select the Fingerprint category in the left hand panel and make sure that Finger 1 is selected in the main settings panel:

Android studio fingerprint emulation.png

Figure 6-6

Click on the Touch Sensor button to simulate Finger 1 touching the fingerprint sensor. The emulator will report the successful addition of the fingerprint:

Android studio 2 fingerprint success.png

Figure 6-7

To add additional fingerprints click on the Add Another button and select another finger from the extended controls panel menu before clicking on the Touch Sensor button once again. The topic of building fingerprint authentication into an Android app is covered in detail in the chapter entitled An Android Fingerprint Authentication Tutorial.

Multi-Core Support

To increase the performance of the emulator Google has added the capability for the Android system image running within the emulator to make use of multiple cores within the processor of the computer system on which it is running. To specify the number of cores used by an emulator, shut the emulator down, load the AVD Manager (Tools -> Android -> AVD Manager) and edit the emulator configuration by clicking on the corresponding pencil icon in the list of emulators. In the Virtual Device Configuration screen click on the Show Advanced Settings button and locate the Multi-Core CPU menu (Figure 6-8) in the Emulated Performance section of the panel. From this menu select the number of cores to be used by the emulator (the total number of cores available will depend on the architecture of the CPU in the system).

Android studio 2 emulator multicore.png

Figure 6-8

Once the setting has been configured, click on the Finish button to commit the change before re-launching the emulator.


Android Studio 2 contains a new and improved Android Virtual Device emulator environment designed to make it easier to test applications without the need to run on a physical Android device. This chapter has provided a brief tour of the emulator and highlighted key features that are available to configure and customize the environment to simulate different testing conditions.