From the first day that I have been using Xamarin for cross-platform development, it was a struggle. One of the biggest pain-points was the use of emulators. While deploying and debugging code on a real device worked, I always had issues with emulators.
My experience with the Android Emulators
I tried using various emulators to run my Xamarin.Droid project. There are various options, such as the Android Emulator from the Android SDK in combination with HAXM (Intel Hardware Accelerated Execution Manager), the Xamarin Android Player (XAP) and others.
I tried many and could not get any to run within a reasonable time frame. I ended up with a recurring list of problems:
- The emulator did not start
- The emulator started but the app could not be deployed
- nothing happened
- I don’t know what happened.
But then, I stumbled upon the “Live from dotNetConf: Cycle 7, Xamarin Studio 6, and more” blog post by Miguel de Icaza, written on June 8, 2016:
In the section “New Mac OS X Universal Installer”, a sidenote mentions that there is a new (and improved) Android Emulator from Google and that there is an improved Hyper-V based Android Emulator for VS2015. And, the last sentence mentions that the Xamarin Android Player (XAP) is therefore officially deprecated!!!
I thought something along the lines of “hm, interesting” and then tried it out. AND IT JUST WORKED!!!!!
I have spent so much time fiddling around with android emulators and I could not believe it. About 35 minutes after reading the blog post by Miguel de Icaza, my app was running in the emulator! No errors, no crash, no frustration! That was the discovery of the day! Jiiihaaaaa…..
The Visual Studio Emulator for Android
The details about the emulator can be found here:
Most important points:
- It requires Hyper-V
- It is fast.
- It can be installed and used without Visual Studio
- It has a lot of features, such as multi-touch, location, driving simulations, accelerometer, screen orientation, SD card, battery, GPS, camera, audio or keyboard.
- It supports device profiles to configure even the most exotic android setups
- You can drag *.apk files onto the emulator for easy installation
- It integrates seamlessly into Visual Studio
There is a great blog post that explains why there is a new Android emulator and what features it provides:
It confirms my experience with the existing emulators and briefly states the reasons why a better emulator experience was necessary.
The following article from Xamarin explains how to use the emulator and what to do if you need Google Play Services:
There is another post that explains how to use the emulator with Android Studio or Eclipse with ADT:
Installing the Visual Studio 2015 Android Emulator
1. Download the installer: https://beta.visualstudio.com/vs/msft-android-emulator/
2. Make sure you have Hyper-V enabled in the BIOS settings
3. Close all running instances of Visual Studio
4. Run the installer
5. Download Devices
After the installer has completed, you can find an application named “Visual Studio Emulator for Android” in your start menu. Run it!
This will start the emulator management application. Select the Android version from the dropdown. You can then pick the devices that you need and download them by clicking the “down arrow” on the right hand side.
6. Start a device
Once the download of the device has completed, you will see a little play button on the right side of the device list. Hit it and the emulator starts (this might take some time. Took about 1-2 minutes on my machine):
7. Deploy from Visual Studio
This is where I got confused. Because I had already installed various other emulators, I had plenty of choices in Visual Studio. Reading the blog posts, I expected the new emulator to show up as something like “VS Emulator 5.2’’ Marshmallow (6.0.0 – API 23)”. Unfortunately, it did not. Since the emulators are Hyper-V based, a quick glance at the Hyper-V Manager gave me a hint:
Finally, I found the emulator in VS named as: “5.2’’ Marshmallow (6.0.0) XXHDPI Phone (Android 6.0 – API 23)”.
From there, I just clicked the button and Visual Studio deployed the app to the emulator. Deploying and launching the app took no more than about 15 seconds (with the Emulator running and no build required).
I think, this is really cool! Good job Microsoft!