Xamarin Tips from the Trenches: Compiling and Emulation for iOS and Android
Xamarin is an exciting environment that allows you to leverage your hard-earned C# knowledge when moving to mobile. But not everything is familiar. For example, the process and tools you use for compiling and emulation vary greatly between the iOS and Android platform. And the choices you make can have a big impact on your edit/compile/debug cycle and thus on your development time. Here you’ll discover the options you have when setting up your environment and information to help which processes and tools are the best fit for your project.
iOS Compiling and Emulation
If you’re programming on a Windows machine, but your apps aren’t targeting Windows or IIS, you need a way to run and test as you do development. For mobile apps you could deploy to a phone or tablet and test it there, but this process can be a little time-consuming. The better option is to use an emulator.
If you are targeting iOS, you may be aware that, although you can develop on a PC, you must compile and run your app on a Mac. This is a restriction Apple imposes, not a limitation of Xamarin. Fortunately Xamarin makes sending your app to a Mac, compiling and running it on an emulator there fairly seamless, once you get it set up. But to make this setup practical, you’ll want to have the PC and Mac screens side-by-side.
Another option is to use a cross-platform remote-desktop solution that will allow you to view and control your Mac in a window from anywhere. There are several free remote desktop applications that would fill the bill, including: Splashtop, Microsoft Remote Desktop and TightVNC.
No Mac? No Problem…
But what if you don’t have a Mac and aren’t really interested in ponying up the cash for a used one?
I just recently discovered an interesting alternative: MacInCloud.com. For $1 an hour or $20 a month, you can have remote access to a Mac for all your compiling/emulation needs! It even comes with Xamarin studio pre-installed. Also included is XCode (Apple’s editor/compiler), the iOS device emulator and a whole lot of other developer-oriented tools.
Android compiling and emulation are much simpler than with iOS since Android may be compiled on a PC and emulators for a variety of devices come with Xamarin.
However, there’s one big problem: The emulators are as slow as molasses. So much so that the environment even warns you when you try to start one!
What to do? First, if you do use the built-in emulators, always launch the emulator once and keep it running. It’s a whole lot more painful if you re-start it each time.
But is there an alternative? Yes, at least two. One option is to deploy to an Android device every time. Though installing and running on the device is certainly not instantaneous, it usually beats waiting for the emulator.
Second, and by far the best solution I’ve found is in a free product called Genymotion. It is a full Android emulator that is blazingly fast. And it integrates with Visual Studio – no configuration monkeying required! Just download and install Genymotion on your machine. You’ll find it at:
Once you’ve launched it, click Add to choose the device(s) you want to emulate. (It has even more device emulation options than those included with Xamarin.)
They will be installed and then you just double click to launch one of them.
Genymotion Virtual Devices
Once the emulator is running, Genymotion will automatically pop up as the default option in your Target Android Device dropdown. (If you don’t see it right away, try re-starting Visual Studio.) Now when you run your app, it will automatically be deployed and run to Genymotion, rather than the default emulators.
Target Android Device Dropdown
The emulator itself provides features through button bars that appear alongside and below the device screen.
The buttons provide the ability to simulate battery status, specify GPS input and the ability to use a PC webcam as a stand-in for the device camera. The grayed buttons indicate additional features that are only available in the paid version.
So if you’re targeting iOS, remote desktop is your friend. Or dispense with the Mac hardware altogether and use a Mac in the cloud. If you’re targeting Android, side-step the built-in emulators and use the speedy (and free!) Genymotion Android device emulator. With these options at hand, you’ll tighten those test cycles and churn out code faster than ever.