Xamarin: My New Mobile Friend

Home / Tech / Xamarin: My New Mobile Friend

Xamarin: My New Mobile Friend

Last month I shared my guidelines for choosing the right method for cross-platform app development projects. In this post, I dig deeper into the world of Xamarin.

As you may have read in my previous post, Xamarin is a cross-platform development tool that allows you to generate native apps with a very large share code between platforms. It aims to solve the dilemma of choosing between a great, but time-consuming and, therefore, costly native app, or a poor, but cheap web app. The illustration above gives you an overview of the different development methods.

Visit my previous post here to get more details.

Xamarin Basics

.Net is the only language you use when writing code for a cross-platform app using Xamarin, and Microsoft’s Visual Studio is the platform most developers choose for the job.

You still need to build specific user interfaces for each platform, however, but Xamarin has created visual designers for each platform to help you with that as well. These designers are almost identical to the ones known from X Code and Android Studio, but an integrated part of Visual Studio.

To put it simply: With Xamarin, you only need to use ONE language and ONE tool to target all the different app platforms. The Xamarin framework has 100% API coverage, which means that you can implement everything you would normally use X Code, SWIFT or Java for, using .Net.

99% Native Code

How can I possibly get native performance on three different platforms using only .Net?, you might ask. The answer is quite simple. Xamarin has developed tools that translate .Net into code into something the different platforms understand.

Here’s a few technical details:

Xamarin applies Ahead-of-Time (AOT) and Just-in-Time (JIT) compilation to both iOS and Android. The .Net compiler generates .Net bytecode instructions that are interpreted by a virtual machine (VM .NET). This bytecode can then be ported to any .NET VM; Windows Phone, Mono on Linux, or JavaScript-based platforms. The interpretation process takes up a little more time than native code execution, but JIT and AOT eliminates that problem.

When a .NET application starts up, the JIT compiler analyzes the bytecode, identifies areas to be optimized by being translated into native code, and compiles them.

Unfortunately, dynamic code generation in general is not allowed by Apple App Store’s terms of service. This means that Xamarin cannot perform JIT on iOS devices. Instead, Xamarin runs a JIT-type compiler ahead of time (AOT), generating machine code for parts of the interpreted bytecode and assembles this in a binary package.

So, AOT translates parts of the interpreted bytecode into machine code. This does not, however, eliminate the need for a .NET VM bytecode interpreter. The VM runs as it would otherwise, but occasionally, an instruction occurs ordering the VM to “finish this as machine code”. In that way, JIT and AOT is what enables native performance on iOS and Android devices.

The Microsoft Acquisition

The future of Xamarin seems very promising. In February this year, Microsoft announced their acquisition of Xamarin. At the Microsoft Build 2016 conference in the end of March, Xamarin was announced as a free product for developers.

This means that with the free version of Visual Studio 2015 (Community Edition) and Xamarin, you can conduct mobile developing from all 3 platforms without purchasing a license.

As a result, all developers now have full access to the Xamarin tool, without extra cost. This is a major milestone within app building.

The acquisition was a natural step in Microsoft’s Windows Universal App strategy, which, in short, entails the aim to make it possible to develop identical applications for all platforms. Microsoft was already porting .Net Core to Mac and Linux, making it possible to use .Net apps here.

Contact Frederik Winstrup if you need to know more fwj@mjolner.dk // +45 41 96 36 56