Friday, March 7, 2014

Xamarin.Android on Visual Studio using VMWare Fusion and Genymotion


Ok the title alone is a mouthful but if you want to use your Mac to write Android apps in C# using Visual Studio, you might want to give this a read.
I know a lot of people out there have invested in powerful Mac setups for development, and you really don’t want to either buy a Windows machine or take the time to set up yet another dev computer.  But you really do want to use Visual Studio for Xamarin.Android development. 
So what’s required?
  • a Mac running OSX 10.8 or later
  • VMWare Fusion
  • A licence for Windows 8
  • Visual Studio, either 2012 or 2013
  • A Xamarin busines license that includes Xamarin.Android
  • Genymotion (which is free for individuals)

Step 1 – Install Windows 8 using VMWare Fusion
Fortunately there’s already a great guide written for that:
http://msdn.microsoft.com/en-us/library/windows/apps/jj945426.aspx

Step 2 – Install Visual Studio in your newly created Windows 8/8.1 VM.  And I’ll assume you can take care of that.

Step 3 – Install Xamarin.Android – you’ll need a Business license but the trial version will suffice if you just want to test it out. http://xamarin.com/ This will install the Android SDK as well.

Step 4 – Install Genymotion on your Mac – we’re going to run it outside of the Windows VM - so on the Mac not the Win8 VM.  http://www.genymotion.com/  And once you have it installed download at least one Genymotion VM to use.

Step 5 – connect Visual Studio to Genymotion
Ok here’s the interesting part, get a Genymotion virtual device up and running and then stretch the window width-wise until you can read the IP address in top right.  In my screenshot it’s 192.168.56.101
Screen Shot 2014-03-07 at 3.48.30 PM
Now go to your Windows 8 VM and open a command prompt.  You’re going to want to navigate to your Android SDK platform tools folder.  If you had the Xamarin tools install the Andrdoid SDK it should be located in:
C:\Users\”Your User Name”\AppData\Local\Android\android-sdk\platform-tools
Once there, run the android debug bridge to connect to Genymotion.  For example:
“adb connect 192.168.56.101” (see screenshot below)
adb-cmd

Step 6 – Start Visual Studio, open/create an Android project and select the Genymotion VM as your Target Android Device.  So far I’ve had good stability with this setup.
geny

Notes – since both VMWare Fusion and Genymotion are virtual machines, only one gets hardware acceleration.  In this setup, on my machine the Windows 8 VM is running without acceleration but its still very usable. 
You can disable hardware acceleration in Genymotion by running Virtual Box, selecting the virtual Android device, click on “Change”, then “System”, then “Acceleration”, and finally uncheck “VT-x / AMD-V”.
This will allow your Windows 8 VM to run with acceleration and Genymotion should still be quick enough to use.