Tim Siefert
Tim Siefert

Reputation: 606

How does Xamarin iOS and Android work?

I try to understand how Xamarin.iOS (MonoTouch) and Xamarin.Android (Mono for Android) work. I wrote a little App and looked into the .app and .apk file.

Inside of the .app file (iOS) are many .dll files. But why? On every page and post I read they say: The App is executed native and nothing is interpreted. Can somebody explain to me what the xamarin developer mean with "native"?

Inside of the .apk file is not a single .dll file..

Upvotes: 29

Views: 14230

Answers (3)

Denis Gordin
Denis Gordin

Reputation: 902

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.

Upvotes: 4

Lex Li
Lex Li

Reputation: 63133

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.

Upvotes: 10

funeralfunk
funeralfunk

Reputation: 163

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

Upvotes: 1

Related Questions