Well, this post is inspired to help a close friend of mine who was struggling to get Xamarin run on Visual Studio 2015 Preview and develop some Xamarin application on Android platform. So I though I will give myself a try with Xamarin on this version of Visual Studio.
I believe in clean start, so if you have any versions of Xamarin installed you should uninstall them. I had a version installed for my Visual Studio 2013 Ultimate Edition and I uninstalled Xamarin. I had to uninstall Xamarin Universal Installer, Xamarin Studio and Xamarin. Give your machine a restart to ensure no pending uninstallations exist.
You don’t need to uninstall Visual Studio 2013 or any other editions you have on your machine.
Creating your Android Project
Open up your Visual Studio 2015 Preview and create a new Project (File > New Project). You will see 2 different templates i.e. Android and iOS.
Select Build native Android apps in C#. Once the new project is created (takes approx. <1 min), you will be prompted with a screen from where you can download Xamarin
Since you don’t have version of Xamarin on your machine, I would recommend downloading Xamarin. If you have any subscription of Xamarin, you can use that subscription. The installer XamarinInstaller-VS2015.exe is of 1.9 MB approx. Remember to close all instances of Visual Studio before going ahead.
If you have gone through Secondary Installation on Visual Studio, probably Xamarin will detect Android SDK like,
It took 4-5 minutes for me for Xamarin Installer to download and install all required components. The official documentation of Xamarin 3.9 that supports Visual Studio 2015 is available at Documentation
After the completion of installation, your Visual Studio New Project dialog will have more templates as shown below
So let’s create a blank Android Application. For the purpose of this post, I will leave the project with default code.
Building the Android App
The first error on build is a resource error
||Access to the path ‘resources.apk.bk’ is denied.
This is typically caused when your Android compilation and Android Emulator have version incompatibility.
To resolve this, right click on Project > Project Properties. Check the Compile using Android version it should be less or equal then your Android API version.
I changed my project settings as shown below
Running the Android App on Mono Emulator
I opened up the Android Virtual Device Manager (Visual Studio, Tools > Android > Open Android Emulator Manager) and saw that there are only 2 Virtual Devices using platform 10 and 12 while I was using version 19.
So if you are not using anything specific to v19 (KitKat), you could downgrade your versions 12 or 10 in the project properties and use the emulator MonoForAndroid_API_12 and run the application to see something like
If you want to use v19, you need to perform some additional steps. You need to open up Android SDK Manager (Visual Studio, Tools > Android > Start Android SDK Manager) and download System Images as shown below
Once this is installed, you can create your new AVD with configuration shown below. This AVD will be stored at C:\Users\%username%\.android\avd
As soon as you create the AVD, Visual Studio 2015 will detect it and show in the Run option
The build may take some time, especially the installation of Mono shared runtime
Assuming that you have set the API properties correctly in Visual Studio when you build your Visual Studio solution for VS Emulator, you may hit another build error which is totally cryptic.
1>Starting emulator: VS Emulator Android Phone
1>Emulator start error: VS Emulator Android Phone
Build has been canceled.
Now this does not provide much detail but the solution to this problem lays in the fact that VS Emulator Android Phone requires Hyper-V Platform to be enabled. There are enough posts on the Internet to enable Hyper-V on Windows 8.1. This should resolve this error for you.
Once Hyper-V is installed, you can open up Hyper-V Manager. You will not see any Virtual Machines in the console but you should be good to start the build and deploy on VS Emulator Android Phone. Your application will appear as shown below
The build & deployment with VS Emulator is much faster (thanks to Hyper-V). When the application is running, you can check CPU and Memory usage in Hyper-V Manager. Note that this CPU usage and Memory for your Emulator (in this case a VM) and not for your application.
As visible in the images, the emulator supports high resolution and has been designed to even support Hi-Res. So this is much easier & elegant way of using emulator than using Mono emulators.
If you face any issues, do comment here..