Android SDK Emulator
- PDF for offline use:
Let us know how you feel about this.
last updated: 2016-11
This guide discusses how to configure and run the default emulator in Xamarin Studio and Visual Studio.
This guide explains how to launch Google's Android SDK Android emulator from Xamarin Studio to test a Xamarin.Android app; it also explains how to create custom emulator configurations. An emulator can be run in a variety of configurations to simulate different devices. Each one of these configurations is created as a virtual device. By default, the Xamarin.Android installer will create a virtual device for each of the Android platforms registered by the installer. Pre-configured virtual devices are available for immediate debug, but it is possible to create custom virtual device configurations that can be launched from the IDE.
To maximize the performance of the Google emulator, it is strongly recommended to install and configure the Intel Hardware Execution Manager (HAXM) to make this emulator run faster. See Accelerating Android Emulators with HAXM for more information.
Using a Pre-Configured Virtual Device
Xamarin.Android can run an application using one of the emulator images that are created during installation. For example, the following pre-configured virtual devices are typically available from the device drop-down menu:
If the Xamarin.Android project is using a target framework level that is incompatible with one or more of the available virtual devices, the drop-down menu lists the unusable virtual devices under Incompatible API Level. For example, the following project has a target framework level set to Android 5.0 Lollipop (API 21), which is incompatible with the XamarinAndroidAPI_15 (API 15) virtual device:
A Xamarin.Android project can be run in one of the emulator images that Xamarin.Android creates during installation. For example, the following pre-configured virtual devices are typically available from the device drop-down menu:
If the Xamarin.Android project is using a target framework level that is incompatible with one or more of the available virtual devices, the drop-down menu lists the unusable virtual devices under Unsupported Devices. For example, the following project has a target framework level set to Android 5.0 Lollipop (API 21), which is incompatible with the XamarinAndroidAPI_15 (API 15) virtual device:
The list of pre-configured devices is automatically created from the platform versions that are available to Xamarin.Android at install time. It is possible to create a custom Android Virtual Device (AVD) image that that is more appropriate for a given Xamarin.Android project using using the Android Virtual Device Manager (as explained in the next section).
Configuring Virtual Devices
Virtual devices are configured via the Android Virtual Device (AVD) Manager. The AVD Manager can be launched directly from the IDE or from the Android SDK Manager.. To launch the AVD Manager in Xamarin Studio, select Manage Android Devices... from the device drop-down menu:
Alternately, launch the AVD Manager from the menu bar by selecting Tools > Open Google Emulator Manager.
The Manage Devices dialog lists the currently configured virtual device emulator images. Click Create Emulator to launch the AVD Manager:
The Android Virtual Devices tab displays the list of existing Android virtual devices:
Virtual devices are configured via the Android Virtual Device (AVD) Manager. To launch the AVD Manager in Visual Studio, click the Android Emulator Manager (AVD) icon in the toolbar:
Launch the AVD Manager from the menu bar by selecting Tools > Google Emulator Manager.
The Android Virtual Device (AVD) Manager dialog displays the list of existing Android virtual devices:
It is not possible to overwrite an existing AVD image. When the Edit AVD button is clicked in the Edit Android Virtual Device (AVD) dialog, the changes are saved to a new AVD. The next section explains how to create custom device definitions and AVDs.
Creating a Device Definition
To create a custom device definition, click Create Device.... This opens the Create new Android Virtual Device (AVD) dialog box. Modify the parameters in this dialog to specify a virtual device and click OK to create it:
To create a custom device definition, click Create.... This opens the Create new Android Virtual Device (AVD) dialog box. Modify the parameters in this dialog to specify a virtual device and click OK to create it:
The results of the new virtual device configuration are detailed in the next dialog:
For a detailed explanation of the configuration properties, see Hardware options.
After clicking OK, the custom device configuration is displayed in the list of existing Android virtual devices:
The new custom virtual device is also added to the device pull-down menu:
Cloning a Device Definition
It is possible to select an an existing device definition and clone it to create a new custom device definition. This is a good strategy to use when there is an existing device definition that needs only a few minor adjustments.
The Device Definitions tab in the Android Virtual Devices (AVD) Manager lists all available device definitions:
The preconfigured devices in this list cannot be modified (only user-created virtual devices can be edited). It is possible to create a new device definition from a preconfigured device by clicking Clone... For example, selecting the Nexus 5 definition and clicking Clone... presents the following dialog:
In the next screenshot, the name is changed to Nexus 5 Custom and the device parameters are modified to create a new custom device definition:
Clicking Clone Device creates the new device definition, which now appears in the Device Definitions list:
Note that each user-created device definition is displayed with a green icon, as shown above. This new device defintion can be used to create a new AVD by selecting the definition and clicking Create AVD.... This displays the Create new Android Virtual Device (AVD) dialog. In this example, we use the generated AVD name AVD_for_Nexus_5_Custom to create a new virtual device:
The CPU/ABI and Skin settings must be specified before the OK button can be clicked. After OK is clicked, the custom device configuration is displayed in the list of existing Android virtual devices, and it is added to the device pull-down menu:
Launching the Emulator
Near the top of the IDE, there is a drop-down menu that can be used to select Debug or Release mode. Choosing Debug attaches the debugger to the application process running inside the emulator. After the virtual device is chosen (from the device drop-down menu), select either Debug or Release mode.Click the Play button to run the application:
The Google Android emulator will start and Xamarin.Android will deploys the app to the emulator and runs it with the selected virtual device image (as illustrated in the screenshot below):
The emulator may be left running, it is not necessary to shut it down and restart it with each time the application is run. The first time a Xamarin.Android application is run in the emulator, the Xamarin.Android shared runtime for the targetted API level is installed, followed by the application. The runtime installation may take a few moments, so please be patient. Installation of the runtime takes place only when the first Xamarin.Android app is deployed to the emulator – subsequent deployments are faster because only the app is copied to the emulator.
If the emulator does not start, HAXM may have to be manually updated (rather than updating HAXM from the Android SDK Manager). HAXM install packages for both Windows and Mac OS X are available from the Intel Hardware Accelerated Execution Manager page. Download the installer that is appropriate for the platform, then run the installer and follow the installation instructions.
This guide explained the process for configuring the default Google Android emulator to run and test an application. It introduced the pre-configured virtual devices, described how to create custom Android Virtual Devices (AVDs), and provided the steps for deploying an application to the emulator.