# Xamarin

## Summary


Xamarin is a cross-platform application development framework. It allows you to develop a mobile app using C# and reuse most of the codebase across multiple platforms including Android, iOS and Windows. Among the advantages of Xamarin are native user interfaces, native API access, native performance and developer productivity. 

Xamarin itself leverages .NET development platform that comes with C# language, its compilers, base libraries, editors and tools. Xamarin extends .NET so that developers can build mobile apps and target multiple platforms.

## Discussion

### When should I use Xamarin?

There are many hybrid and cross-platform frameworks to develop apps across multiple platforms, but these require skills in JavaScript and are best suited for Web developers. For them, Apache Cordova is one possible framework but do keep in mind that this is a hybrid approach that will not give native performance. 

Where performance is desired along with faster time to market via multiple mobile platforms, Xamarin must be preferred. Xamarin is best suited for developers coming from .NET, C# or Java backgrounds. 

As a note, Xamarin should not be confused with **.NET Core**, though both are cross platform and open source. Xamarin is for cross-platform mobile (though it can be used for MacOS) whereas .NET Core is for creating cross-platform web apps, microservices, libraries and console apps that can run on Windows, Linus or MacOS. 


### Why should I use Xamarin?

Xamarin helps to expedite native mobile app development targeting multiple platforms. It's been said that for informational apps, 85% of code can be reused across Android and iOS. For more intensive apps, code reuse of 50% is possible. This code reuse comes from using shared C# app logic across platforms. 

User interface code itself is not shared by Xamarin but that's where **Xamarin.Forms** comes in. Using **Xamarin.Forms** 96% code reuse has been reported. 

For developers, this means that you get to build native Android, iOS and Windows Phone apps concurrently without having to build them one after another or having multiple teams with multiple skillsets and tools.

**Xamarin.Android** and **Xamarin.iOS** provide further customization possibilities for developers who are looking at tweaking the app's look and feel achieved with Xamarin.Forms. There are several other benefits like seamless API integration, easy collaboration and sharing, etc. 


### Could you describe some useful Xamarin-specific terms that developers should know?

The term **managed code** refers to code that's managed by .NET Framework Common Language Runtime. In the case of Xamarin, this is the Mono Runtime. In contrast, **native code** is code that runs natively on the platform. Managed code could be in C# or F#. Java/Android code are native to Android; or Objective-C code is native to iOS/MAC. 

During compilation, C# or F# code is converted to **Microsoft Intermediate Language (MSIL)**. In Android and Mac platforms, MSIL is compiled to native at runtime using **just-in-time (JIT)** compilation. In iOS, due to security restrictions, this is not allowed. Hence **ahead-of-time (AOT)** compilation is performed. 


### What's the architecture of Xamarin?

Architecture is described in the documentation in three places:

    + Xamarin.Android Architecture
    + Xamarin.Mac Architecture
    + Xamarin.iOS ArchitectureIn general, C# code and .NET APIs sit on top of Mono runtime, which in turn sits on top of the OS kernel. Architecture allows for managed code to invoke native APIs via bindings. In Android, **Managed Callable Wrappers (MCW)** are used when managed code needs to invoke Android code; **Android Callable Wrappers (ACW)** are used when Android runtime needs to invoke managed code. There's also the **Java Native Interface (JNI)** for one-off use of unbound Java types and members. 


### How much does it cost to use Xamarin?

Xamarin was initially available for a license. After it was acquired by Microsoft in 2016, it's now bundled with the Visual Studio suite of tools for free. While Visual Studio is not completely free, there is a Community Edition, which is free for eligible companies and developers.

The .NET platform itself open source and Xamarin in part of it. This means there are no fees or licensing costs, even for commercial use. 


### What are the pre-requisites for Xamarin app development?

To develop the app, one should have good programming expertise in C#, assuming that the RESTful APIs required for the application are already available. A Windows PC will be required for development on Android and Windows platforms. iOS development is done on Windows PC but to build the app, a Mac will be required to be connected in the same network as per Apple's requirements. 


### How does Xamarin compare against other cross-platform frameworks?

Among the cross-platform mobile frameworks are React Native, Ionic 2, Flutter, NativeScript, and Xamarin. Ionic 2, React Native and NativeScript rely on web technologies (HTML/CSS/JavaScript/TypeScript). Ionic 2 can suffer from performance problems. While Ionic 2 uses WebView (basically HTML wrapped in a native app), React Native and NativeScript use native UI components. Ionic 2 can also allow access to native API but will require the use of Apache Cordova. Xamarin uses native UI components and offers good performance. 

For development, Xamarin lacks automatic restarting and hot/cold swapping. In this aspect, React Native is one of the easiest for developer productivity. All frameworks allow native code bindings but this process is easiest on Xamarin. Xamarin offers full one-to-one bindings to native libraries whereas in React Native or Ionic, support is partial and done via an abstraction layer. 

A blog post from AltexSoft compares the performance of Xamarin apps against native apps. It concludes that performance drop due to Xamarin is acceptable for most cases but the use of Xamarin.Forms is not recommended when apps are CPU intensive. 


### What are some criticisms of Xamarin?

It's been said that Xamarin support for latest platform updates (iOS/Android) are usually delayed. While iOS and Android developers can tap into an active ecosystem plus use open source technologies, similar following is limited in Xamarin. Xamarin is also not suited for apps that are heavy for graphics, where code reuse will be limited. For that matter, Xamarin developers still need to learn platform-specific languages for the UI, unless they also adopt Xamarin.Forms for their apps. 

Xamarin apps are also larger in size when compared to equivalent native apps. This is because the app has to include the Mono runtime and associated components. A simple "hello world" Android app written in Xamarin requires about 16 MB. 


### Where can I learn more about Xamarin?

Xamarin has excellent documentation and code samples at their website. Specific official resources from Microsoft include:

    + Documentation
    + Courses, tutorials and videos
    + Community forums
    + The Xamarin Show on MSDN
    + Xamarin tutorials on Microsoft Learn
    + Visual Studio tools for XamarinThere used to be Xamarin University to train and certify professional developers. Since June 2019, this is now part of Microsoft Learn platform. 

## Milestones

1999

Miguel de Icaza and Nat Friedman start **Helix Code** for GNOME desktop application development for the Linux platform. In 2001, this is renamed to **Ximian**, which is acquired in 2003 by Novell. 

2000

Microsoft releases .NET Framework and Visual Studio .NET along with introducing a new language named C#. 

2001

**Mono** project is launched for supporting .NET applications on non-Windows platforms. Open source and based on .NET Framework, Mono enables developers to build cross-platform applications. 

May  
2011

**Xamarin** as a company is incorporated with the idea of building commercial .NET offerings for iOS and Android. In July, Novell gives Xamarin the rights to use MonoTouch and Mono for Android. 

2016

Microsoft acquires Xamarin and releases Xamarin as part of Visual Studio suite of tools.