Skip to content

Setting up a Cross Platform Build Environment

Andrew Coates edited this page May 13, 2014 · 5 revisions

I've been doing cross-platform development for a little while now using Visual Studio 2013 and [Xamarin] (http://xamarin.com), along with MvvmCross, but getting things set up to do development across iOS, Android, Windows 8, Windows Phone and WPF is a non-trivial task. I couldn't find a comprehensive set of instructions for setting up a development environment that made developing, deploying and testing all of those platforms as simple as possible.

Here's my attempt at such a set of instructions.

Hardware

Required Hardware

To do Windows (8/Phone/Desktop) development, you need a machine running windows. To do iOS development (or at least to build) you need a machine running OSX. To do Android development, pretty much any O/S will do, so you may as well choose one of the first two.

There are a couple of options here:

  1. Have separate physical machines for OSX and Windows
  2. Run Windows in a VM on a Mac

I actually do both. My home setup is a Lenovo X220 (i7, 512GB SSD, 8GB RAM) hooked up to a couple of Dell 27" monitors and a 4GB Mac Mini to act as my iOS build server. My mobile work setup is a 15" MacBook Pro with 16GB RAM, a 512 GB SSD running Windows 8.1 Update 1 in a VMware Fusion virtual machine. This is the setup I'll be describing below, but the other one is not too dissimilar.

Optional Hardware

While the setup I'll be describing allows you to run emulators/simulators for all of the target devices, you may also want physical devices. These can be pretty much anything that runs your target environment, but I'd recommend getting as low-end devices as possible as a general rule as this will expose performance issues more readily. I'll discuss connecting physical devices to your environment later.

Software

Mac

Xamarin

On your Mac, whether you're hosting a Windows VM or not, you're going to need the latest build of XCode, as well as the [Xamarin tools] {http://xamarin.com). For Visual Studio integration, including running a build server that your VS instance can use, you're going to need at least the Business edition. Note that if you're an MSDN subscriber, there's a [discount available] (http://xamarin.com/msdn) from Xamarin. If you do the default install of the Business Edition of both Xamarin.iOS and Xamarin.Android, you'll also get the Android developer tools on your Mac.

VMware Fusion

For my work setup, I needed a virtual environment on the Mac so I could run Windows on the same box. I chose VMware Fusion. I needed to be running both Mac and Windows simultaneously, so dual-booting wasn't going to work. Importantly, Fusion allows me to run both the Windows Phone and the hardware accelerated Android emulators in the virtual machine.

I grabbed Fusion from the [VMware Site] (http://www.vmware.com/au/products/fusion/) and installed it. I then kicked off the new machine wizard

Fusion Windows Install 1

I had previously got the Windows 8.1 ISO image from MSDN so I pointed at that ![Fusion Windows Install 2] (http://s23.postimg.org/fj2giydnf/Fusion_Windows_Install_2.png)

Filled in some details including the Product Key from MSDN

![Fusion Windows Install 3] (http://s23.postimg.org/55683giaj/Fusion_Windows_Install_3.png)

On the next screen, I chose More Isolated. The first time I went through this process, I chose the "More Seamless" option and had no end of trouble with permissions in shared locations, so this time I went with "More Isolated".

![Fusion Windows Install 4] (http://s23.postimg.org/yujevt1gb/Fusion_Windows_Install_4.png)

On the next screen you need to choose the Customize Settings button, because by default Fusion isn't giving you nearly enough grunt.

![Fusion Windows Install 5] (http://s23.postimg.org/57q3qaly3/Fusion_Windows_Install_5.png)

Give it a name and then update the following:

General

  • Turn on Start Automatically

![Fusion Windows Install 6] (http://s23.postimg.org/kpdltzsez/Fusion_Windows_Install_6.png)

Processors and Memory

  • Select 4 Processor Cores
  • Allocate 10000MB Memory
  • Under Advanced options, Enable hypervisor applications in this virtual machine

![Fusion Windows Install 7] (http://s23.postimg.org/ji49firob/Fusion_Windows_Install_7.png)

Hard Disk

  • Allocate 200GB

![Fusion Windows Install 8] (http://s23.postimg.org/foat6dacb/Fusion_Windows_Install_8.png)

Close the settings dialog and hit the play button in the middle of the Fusion screen

![Fusion Windows Install 9] (http://s23.postimg.org/e1lll4yaj/Fusion_Windows_Install_9.png)

Fusion chugs through the install process for a while (this might be a good time to make sure OSX is up to date and to check on the Xcode install)

Before too long (mine took < 5 minutes), you have Windows up and running in a window on the Mac. Log in and apply all updates (this can take a looong time – over 2 hr for me with a couple of restarts and checks for more updates – in hindsight, it would have been quicker to download the 3.6GB ISO with the 8.1 update applied, rather than using the older 8.1 ISO I had and applying all the updates)

You may see a dialog telling you VMware Fusion has changed the interface size. If so, just let it log out and log back in again. This is just scaling the display so you can read it on the high-resolution, high-dpi screen of the Mac.

Finish installing all the updates (keep checking until there are no more).

The last thing I like to do is link my Microsoft Account to the login so I can use it to connect to all my services, roam my settings and so on.

Finally, take a snapshot. This means you've got a known state to build your dev machine on.

![Fusion Windows Install 10] (http://s23.postimg.org/5tjo056e3/Fusion_Windows_Install_10.png)

![Fusion Windows Install 11] (http://s23.postimg.org/6514cwmu3/Fusion_Windows_Install_11.png)

Windows

Visual Studio

Now you've got a Windows VM, it's time to install your developer tools. From inside the VM, I headed over to the MSDN site and installed the RC of Visual Studio 2013 Update 2. Depending on when you're reading this, you may have a different latest VS, but whatever that is, grab it and run the install. I made sure I had the Windows Phone 8.0 SDK and the Widows 8 Store Apps options selected (which meant I ended up with everything, a bit over 13GB).

One of the things to watch out for here is that if the Windows VM or the OSX host go to sleep, the install stalls, so make sure you set your power settings to "never go to sleep" while you're installing.

At this stage, I took another snapshot so I had a stable base to restore to should anything go wrong in the following steps.

Once the install's done, open VS and sign in with a Microsoft Account (formerly known as a LiveID). If you've already done this on another machine, all of your settings etc. will be migrated across to this instance.

Go to the Tools | Extensions and Updates menu and apply any updates offered. In my case, there were five things to update, but depending on when you're doing this, there may be more or less for you.

I took another snapshot here. You may not want to depending on how much free space you have. You might also want to investigate putting snapshots on an external drive, something I haven't yet explored.

Xamarin

Now it's time to get the Xamarin tools on your Windows VM. Head over to the Xamarin website and sign into your account (which you would have set up in the Mac section above, if not before). Go to the downloads section and get the Xamarin for Windows tools. This will download and run an installer which will get all of the tools you need to do both iOS and android development from Visual Studio. This chugs away for a while installing

  • Java
  • The Android SDK
  • GTK#
  • Xamarin Studio
  • Xamarin.Android
  • Xamarin.iOS

Running Hypervisor-based Emulators under VMware Fusion

One of things I really needed to be able to do on the Windows VM was run emulators for both Windows Phone and Android. It's possible to run the Android emulators on the Mac (with hardware acceleration) or on the Windows VM with software emulation only (note: you DO NOT want to do the latter, it is SLOW).

Windows Phone Emulators

The Windows Phone emulator though, must be run on Windows and it requires access to the CPU's Hypervisor. If you try to start the emulator (from Visual Studio or from the rather excellent new Windows Phone Developer Power Tools (8.1)), a skin will appear, and then you'll get a message telling you that it can't connect to the virtual machine and that some component of Hyper-V may not be running.

Fortunately, you can fix this. A chap named Pascal Arnould from Endjin has posted [instructions on how to do so] (http://blogs.endjin.com/2013/06/running-the-windows-phone-emulator-in-vmware-fusion/). His instructions show screenshots from Fusion 5, but under 6 it's pretty much the same. Follow those instructions and you're in business for the Windows Phone emulator.

Android Emulators

You really want to run a hardware accelerated Android emulator too. The default emulators are software only and they are really slow. So slow that it's detrimental to the develop/build/deploy/test cycle. Fortunately (once again) Intel have released the [Intel® Hardware Accelerated Execution Manager] (http://software.intel.com/en-us/android/articles/intel-hardware-accelerated-execution-manager) (HAXM). They've got a [comprehensive document explaining what HAXM is] (https://software.intel.com/en-us/android/articles/speeding-up-the-android-emulator-on-intel-architecture), and the most recent instructions I found for installing HAXM is [here] (https://software.intel.com/en-us/android/articles/installation-instructions-for-intel-hardware-accelerated-execution-manager-windows).

If you're struggling to find the Android SDK manager on your VM, have a look in the Apps section of the Windows 8 Start screen (swipe up or click the arrow at the bottom of the Start Screen.

![Finding the Android SDK Manager] (http://s23.postimg.org/rv5cwg1i3/Finding_the_Android_SDK_Manager_12.png)

Note that after you've "installed" HAXM from the SDK manager, you've actually only downloaded it, you still need to run the installer. Read the doc :). There are some great Tips and Tricks at the bottom of the installation instructions document about tuning and troubleshooting. For example, enabling GPU acceleration for your emulator images.

Once you've downloaded and installed HAXM, you need to define one or more emulator images to run. The instructions for doing this are [here] (https://software.intel.com/en-us/android/articles/speeding-up-the-android-emulator-on-intel-architecture#_Toc358213274). I recommend creating a phone-sized image and a tablet-sized image.

Pairing Visual Studio with the Xamarin.iOS Build Host

To build iOS apps, Visual Studio has to pass off the build to XCode. The Xamarin guys have built a neat little bridge that makes that process very developer friendly. On your Mac, launch the Xamarin.iOS Build Host (I set this to auto-launch when I start OSX). The first time you launch it, you'll be presented with a Pair button:

![Xamarin.iOS Build Host] (http://s23.postimg.org/gcjnpb923/Xamarin_i_OS_Build_Host_13.png)

Click Pair and you'll get a 6 character alpha-numeric code and the option to copy it to your clipboard. Go ahead and copy it.

Next, go into your Windows VM and start Visual Studio.

  1. Go to Tools|Xamarin Account… and login to your Xamarin Account.
  2. Go to the Tools|Options dialog, expand the Xamarin node and select the iOS Settings sub-node
  3. Click the Find Mac Build Host button, and then click Continue.
  4. Select your Mac in the build host list and click Connect
  5. Paste the PIN you copied onto the clipboard into the big box where it says Enter PIN (yep, Fusion lets you share clipboards between Mac and Windows – cool huh?) and click Pair
  6. You should see a green tick of success. Click Finish and then OK to close the settings dialog.

Note that generally, this is the only time you'll have to go through the pairing process as both components are supposed to remember and re-establish the connection.

Connecting Physical Hardware for Deployment and Testing

Windows Phone

Connecting a Windows Phone is the easiest of the physical devices. You need to unlock your phone for development and then whenever Visual Studio detects that the phone is plugged in, it will make one of the deployment targets "Device".

To unlock your phone, you'll need a developer account (sign up at http://dev.windowsphone.com). Note that this account is now good for both the Windows Phone and Windows 8(.1) stores.

Run the Windows Phone Developer Registration tool that comes with the Visual Studio install (you should be able to find it in your Apps screen, the same way you found the Android SDK above). You'll get a dialog like this:

![No phone attached] (http://s16.postimg.org/je05p12hh/Developer_Registration_1.png)

Depending on whether you've got a phone plugged in, whether it's powered on and whether it's unlocked, the status message will be different from above.

Once you have a phone plugged in, powered on and unlocked, a different button will appear:

![Ready to register] (http://s16.postimg.org/oqp035qdx/Developer_Registration_2.png)

Click Register and you'll be prompted to sign in using the Microsoft Account associated with your developer account.

Successfully doing so will unlock your phone and the status text and the button will change again:

![Success] (http://s16.postimg.org/bjzk3muol/Developer_Registration_3.png)

Your phone is now in a condition that will let Visual Studio use it as a deployment and debugging target. By default, you can register up to three developer unlocked phones. If you need more than this, raise a support ticket on the http://dev.windowsphone.com site asking them to lift the number.

There's more information about registering your phone for development (including troubleshooting and unregistering phones) on the [Windows Phone Dev Center] (http://msdn.microsoft.com/en-us/library/windowsphone/develop/dn614128.aspx).

Windows 8

In general, I run Windows Store apps on the local machine (in this case, in the Windows VM itself). However, it is possible to connect to another device (for example, one with Touch, or one running Windows RT). There are great instructions on MSDN on how to do that:

Android

There are a number of steps to making a physical android device available for debugging. The best guide I've found for making this work is from Xamarin – [Set Up Device for Development] (http://docs.xamarin.com/guides/android/getting_started/installation/set_up_device_for_development/).

In a summary, the steps are:

  1. Enable Debugging on the Device - By default, it will not be possible to debug applications on a Android device.
  2. Install USB Drivers - Windows computers may require the installation of USB drivers. I had to download the [Samsung Android USB Driver] (http://developer.samsung.com/android/tools-sdks/Samsung-Andorid-USB-Driver-for-Windows) for my Galaxy Express. I still haven't found how to do this for my Lenovo.
  3. Connect the Device to the Computer - The final step involves connecting the device to the computer by either USB or WiFi.

[Read the article] (http://docs.xamarin.com/guides/android/getting_started/installation/set_up_device_for_development/) for the details.

iOS

[Coming Soon]

Presenting/Demoing from this Configuration

Presenting In Person

[Coming Soon]

Presenting Online

[Coming Soon]

Recording Web/Screencasts

[Coming Soon]

Clone this wiki locally