Speeding up the Android emulator and fixing Xamarin debuging issues

Android emulators can be a bit slow and when I say slow, I mean REALLY slow. This article attempts to cover a two of the most prominent issues when using an Android emulator with Xamarin. Its speed and how buggy the debugging can be. If that makes sense. :/

So you're using Xamarin to build an app and all of a sudden, one day, out of the blue, like Xamarin just decided to hate you, it get's stuck on Starting emulator... or it just takes AGES to start debugging, chances are you're running your emulator with a virtual ARM CPU, yup... Slow.

Solving the slow AVD and buggy integration between Xamarin and AVD:

To solve the issues, you'll need to change your virtual device from an ARM CPU to an Intel Atom, to do this, click the icon in the toolbar that looks like a phone with a play button over it, like so:

Xamarin Visual Studio AVD button

This will open up the Android Virtual Device Manager and within it, you should have a list of virtual devices that Xamarin can use to debug Android apps within, we're going to want to change one of these to an Intel Atom CPU, as you can see below, I've already changed one of mine so you can see the difference within the AVD.

List of Android virtual devices with mixed CPUs

Note: You may notice that none of my virtual devices names contain spaces, this is because there was a known issue with the virtual names containing spaces and Xamarins ability to use them to debug so this might be worth a thought if you run into this issue.

Now you'll need to click one of the devices in the list and then click the Edit... button, this will allow you to change the device name and configuration. You should now have been presented with a new window that looks like this:

Edit a virtual Android device settings and configuration

So if you wanted to change the name, now is the time to do it, just update the text within the AVD Name field.

You'll now need to choose the Intel CPU from the CPU/ABI dropdown, just click it and choose Intel Atom (x86), now you'll need to change the VM Heap to 256 and give your device more ram if required. I tend to allow 2048.

Note: When Use Host GPU is checked, you cannot also have Snapshot checked.

If you want to speed up rendering, make sure that the Use Host GPU checkbox is checked.

Now click OK and you'll be presented with another window with the heading Result of creating AVD, click OK on that too as this window is just informational.

Making sure the final bits are installed:

In order to correctly emulate an Intel Atom CPU, you'll need to install Intel HAXM, just scroll down on the page, click to download the zip, agree with the terms, wait for it to download, extract it and install leaving all the settings default.

Chances are the AVD will now work, but if you have Hyper V running, you'll need to turn that off so that the Intel Virtualisation can run correctly, simply open up CMD with administrative rights and run the following command and when it's done, reboot:

bcdedit /set hypervisorlaunchtype off

That's it, you're good to go and your Android Virtual devices should now run at least x10 faster and Xamarin should deploy apps to it with ease.

Xamarin won't launch your app?

Your app might crash on startup with the error 'android emulator shared runtime initialization error' despite the virtual device now running very quick. This can be caused by the change in CPU on the virtual device, put simply, Xamarin uses a shared mono runtime to run its apps in debug, this is installed the first time you debug a Xamarin app, however if the device CPU changes, the binaries are now incompatible.

To solve this issue, uninstall Mono Shared Runtime and Xamarin Android API support from the Apps section within Settings, then simply Clicking play within Visual Studio will re-install both of these and your app should boot up as expected without issue.

Summary.

You can speed up Android Virtual Devices by swapping from an ARM CPU to an Intel Atom CPU.

A faster AVD will allow Xamarin to make requests of it in a timely fashion solving some issues.

Intel HAXM is required to emulate an Intel Atom CPU.

Mono runtime will need to be reinstalled.


Published at

Tags: Android,Xamarin

Luke Alderton

Comments

Share with
Tags
Latest Comments
By Mark Gentry on Windows Server 2019 - Change product key does nothing
20 Aug 2021, 03:30 AM
By Cathy on In-Place Upgrade for a Windows Server domain controller
31 Jul 2021, 18:28 PM
By Mr. Greymatter on Raspberry Pi - Running Java app on Raspbian
16 Feb 2021, 07:35 AM
By Mikko Seittenranta on Xamarin Forms multiple instances of same app open
16 Feb 2021, 04:34 AM
By Andrew on Auto/Custom height on Xamarin Forms WebView for Android and iOS
22 Jan 2021, 22:15 PM
By Nick on Raspberry Pi - Running Java app on Raspbian
14 Oct 2020, 19:37 PM
By Ivan on Fixed: Value cannot be null Parameter Name: source
15 Sep 2020, 19:47 PM
By Anand on Raspberry Pi - Bluetooth using Bluecove on Raspbian
7 Sep 2020, 16:53 PM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development