What is your C# code doing within a Xamrin build? - xamarin

I've read through a lot of documentation on Xamarin and my understanding is that it exposes the native APIs on each platform via C# and .NET, and this way, offers a sort of one-to-one binding. The native build produced contains some of the applicable .NET libraries (based on linker optimisation).
However, I can't seem to find any information about what actually happens within the native build itself.
Assuming my understanding is correct, my question is:
Within the native build, does the code you've written call the native API functions via a call to native .NET functions included in the build?

The short answer is: yes, it calls native API's through .NET code that runs on Mono, via the binding concept you already seem to be familiar with.
Xamarin uses these bindings to call the native code from your C# code. There are a few differences depending on the platform you are running on.
iOS
Your IPA-file will contain 2 things:
The executable of your .NET code (AOT-compiled), which is run through the Mono runtime
Native libraries, which use the objective-C runtime. The .NET code calls these libraries/API's via bindings.
Both the Mono runtime and the Objective-C runtime are running on top of a UNIX-like kernel.
Take a look at this Xamarin iOS architecture documentation for a more extensive explanation.
Android
Android is a little more complex to understand and explain. This is because some of the API's are only exposed through the Android Runtime API.
The bindings in Android are working through concepts such as:
"Android Callable Wrappers" (Android Runtime to Mono)
"Managed Callable Wrappers" (Bindings to Android Runtime API's)
The Xamarin Android architecture documentation explains these concepts and inner workings in great detail.

Related

Is it possible to create native Android and iOS library with Xamarin? [duplicate]

Currently, we are developing a .NET Standard class library that will be used by different Xamarin.* platforms.
I was wondering if there is a way to use the shared code in a native Android project (maybe produce an AAR/JAR file).
The reason I need this functionality is because our company provides an AAR to one of our customers (that is used by a native Android project), and we would like to keep a single source base instead of two.
Thanks in advance!
Update:
The name changed to ".NET Embedding" and it is at v0.4 at the time of this update.
https://developer.xamarin.com/releases/dotnetembedding/dotnetembedding_0/dotnetembedding_0.4/
New instructions:
Installing .NET Embedding
Original post:
You can use Mono's Embeddinator-4000
It supports various language consumers, so it surfaces .NET code as idiomatic code in the target language. This is the list of supported languages at present:
Objective-C: mapping .NET to idiomatic Objective-C APIs.
Java: mapping .NET to idiomatic Java APIs.
C: mapping .NET to an object-oriented like C APIs.
Embeddinator-4000 is a tool that allows your existing .NET Code (C#, F# and others) to be consumed from other programming languages and in various different environments.
Java is currently in a preview state for macOS, Windows, and Android.
The platform is selected by passing the --platform= command-line argument to the embeddinator. Currently macOS, Windows, and Android are supported.
re: https://mono.github.io/Embeddinator-4000/
As a part of the requires For Android you will need Xamarin.Android 7.4.99+ and Android Studio 3+ (Java 1.8) but if you are building Android apps with Xamarin and Java you would have those already.
Note: This tool is in Preview, so review the open issues and post new if needed.
re: https://github.com/mono/Embeddinator-4000/issues
Note: This is not trans-compiling, but embedding Mono's runtime in a native package that allow CIL code, AOT'd (i.e. iOS) or not to run within a different language/runtime.

Xamarin Cross Platform Development .net

We are developing a cross platform mobile application using Xamarin. I have noticed there are different ways of structuring your code using Shared code or PCL/.net standard.
I attempted to use .net standard and what i have found is that it doesn't include all the libraries such as using ado stuff , datatable/datasets using system.data. Or using system.net for example. Other functions have less overloads and seems that its a stripped version of .net to work across platforms. Is there any way to add this functionality or use a broader range of .net?
You are correct - .Net Standard and .Net Core are stripped down versions of the full .Net framework. They contain only features that can be used on all platforms (Mac, Android, iOS, Linux, Windows, etc.)
The full .Net framework only needs to work on Windows, so there are additional things that you can do based on the fact that there is less complexity in implementing and that the code base is more mature (cross platform is still pretty new by C# standards). To the best of my memory, System.Net should work if you have your references correct, but System.Data will not (or at least direct database access is not possible)
You can regain some functionality through NuGet packages, but it won't be the same as using WinForms or something like that...
My best advice would be to program against an API. You can use a web server that runs on the normal (full) .Net framework, and does all the heavy lifting using all the .Net features that you are accustomed to. Your Xamarin app would send and receive data from the API and basically provide a mobile front end for whatever you are doing. This approach makes sense for most apps anyway, and is generally what you would be doing anyway if you used Swift and Java to create separate iOS and Android apps.

How do you compare (ReactNative, NativeScript) to Xamarin?

Since [ReactNative/NativeScript] uses JavaScriptCore/V8 JIT interpreters and not compiling it so, is it strong enough for building all types of apps e.g. (Mediaplayer, Photo Editing, etc…)?
And how do you compare it with Xamarin?
I heard Xamarin uses AOT; is it similar to (JavaScriptCore/V8) JIT interpreters?
And how often Xamarin uses AOT for all of the app or it compile the part of code to native and uses AOT for rest of it?
Many Thanks in Advance.
Xamarin does AOT for its C# code, which will be run by open source port of .NET -Mono in non windows platforms like Android and iOS. Here are some limitations on Xamarin AOT
In comparison, Nativescript with Angular 2+ can take advantage of the Angular AOT for performance boot. More details here.
Here is a detailed comparison from Progress, the company that backs NativeScript and also provides UI elements for xamarin.
With more traction towards JS open source community, JavaScript virtual machine growth vs Mono for .NET, current benchmarks, I would bet on NativeScript/React native more than Xamarin.
NativeScript / React Native is a good bet, including your media player kind of app.. here is a sample you can give it a try.
Hope it helps.

Is it possible to use haxe to build mac native application?

I see Haxe can compile to many languages, but not sure is it possible to use it build a native mac(OSX) application? Like a small TODO list application?
Yes, using OpenFL or other framework (Luxe, Kha, NME) you could target Mac and get project that compiles via XCode into native application.
If you want native OSX UI then there are libraries for that, such as Basis: https://github.com/Randonee/Basis. When using that you use the C++ target, and the library communicates with Objective C UI stuff via the C Foreign Function Interface. This comes with some limitations and depending on the status of the library, it could be hard to get started.
If you don't care about native UI then there are libraries that have what you need for simple notepad-type apps. In most cases you would still be able to use the C++ target. For example see Ian Harrigan's Haxe UI project: https://github.com/ianharrigan/haxeui

Is it possible to write shared libraries between iPhone, Android, Blackberry, Mac and Windows?

I'm tasked with "porting" a few apps from a Windows environment to various mobile platforms and Mac as well.
I plan on writing MVC patterned apps in which I write as many controllers as I can in some sort of universal library, probably in C or C++. Then writing the views in various choice languages (Objective C, Java, .NET, whatever) for the target OSes.
I've never attempted anything like this before, so my questions are: Is it possible to write and compile one library that can be used on iPhone, Android, Blackberry, Windows and Mac? Is it even wise to try this?
I understand that certain native methods simply won't be available on each platform.
You can create a library whose source code is portable, assuming that you properly abstract away any platform-dependent calls. You can't, however, create such a library, compile it, then use it anywhere; you'll have to compile it for each platform.
Your should take a look at the Mono Project. http://www.mono-project.com
...more specifically at :
MonoTouch: To develop iPhone applications in .NET
MonoDroid (BETA): To develop Android applications in .NET
Mono plugin for MeeGo: To develop MeeGo applications in .NET
And you know that you can develop on Windows Mobile in .NET already.
I've haven't found anything related to BlackBerry yet.
There are services like Rhomobile and Appcelerator which will allow you to do this sort of cross compiling.
I've never used either however.

Resources