How does Xamarin iOS and Android work? How does Xamarin iOS and Android work? android android

How does Xamarin iOS and Android work?


The Xamarin definition of "native" includes but is not limited to:

  • Every line of C# code is compiled to machine code and then packed in .app. There is no JIT at runtime, as it is suppressed by AOT. More information can be found at

http://www.mono-project.com/AOT

(Note that Xamarin.Android still uses JIT, http://xamarin.com/how-it-works)

  • Access to platform native types / API is fully open, so you are not limited to a small set of API calls (if you use HTML5 / JavaScript, you know what kind of limitations are there).

  • The user interface you design is bound to the native API exposed by iOS (CocoaTouch) or Android (Skia). There is no intermediate layer to hurt performance or look and feel.

As to what is inside .ipa or .apk, who cares? Of course @Jason's comment shows us of some internal implementation details.


First of all, Xamarin works on two different runtimes at same time:

  • Mono
  • Native runtime (Davlik, ART, iOS runtime)

Some example. When you are creating your own C# class in Visual Studio, instance of this class will run under Mono. Also when you are downloading Newton.Json package from nuget, this will run in Mono too. This is reason why we can use all cool .NET stuff. However, when you are inheriting from Java.Lang.Object (Android) or NSObject (iOS) or making a custom controll, instances of these classes will run under native runtime.

Second of all, you can noticed that we need bind these two worlds somehow. Let's have a look what type of objects do we have.

  • Managed objects (Mono)
  • Unmaneged objects (Native world)
  • Peer objects (Mono, objects which is wrappers for native objects)

Peer objects it's instances of Xamarin SDKs classes (for example activities, view controls, UILabels, TextViews and so on), instances of your own inheriting from Java.Lang.Object, NSObject, Fragment or even UISegment classes.

That mechanism is one of most important things from Xamarin.

PS: Actually, it does not matter which of compilation do we use for Xamarin projects JIT or AOT. It depends on platform and allows / not allows some features from .NET world. That does not describe how Xamarin works.


The Xamarin compiler bundles the .NET runtime and outputs a native (binary) ARM executable, packaged as an iOS or Android app.