We continue our tech series on cross-platform mobile development and today we’ll talk about Xamarin. Xamarin is well known as an efficient framework for cross-platform development and is highly valued due to its speed and rich functionality. As well, you’ve probably heard that by the end of 2021, Xamarin will become .NET MAUI as part of Microsoft’s plan on the .NET consolidation. Below, we will talk about Xamarin, its most outstanding features, and what its change to MAUI will mean for the community.
Xamarin: a brief history and the current state
Xamarin has a long and somewhat complicated history. Officially, Xamarin started in 2011 but it would be more correct to trace it back to the early 2000s. That’s when the Mono project was created.
Mono is an open-source project that was initially created by Miguel de Icaza in an attempt to provide a .NET version for Linux. And in 2011, de Icaza announced Xamarin which was designed to replace MonoTouch and Mono for Android. In 2016, Microsoft acquired Xamarin and this acquisition resulted in the following: Visual Studio now includes Xamarin and Xamarin SDKs became open-sourced. As you can guess, Xamarin relies on .NET heavily and thus provides its developers access to numerous valuable features (we’ll discuss them below).
It is important to mention that Xamarin has two main types: Xamarin.Forms and Xamarin Native. Each of them has its own benefits over each other, but the conjunction of both makes Xamarin highly competitive over other cross-platform development technologies.
Today, Xamarin is still being in use though it’s not so popular as other cross-platform frameworks. In 2020, the Stack Overflow survey stated that Xamarin was used by 5.8% only while React Native and Flutter had 11.5% and 7.2%, correspondingly. And while it’s not the top developers’ pick according to statistics, Xamarin is well-recognized and used by companies like Siemens, BOSCH, Honeywell, Cognizant, and JetBlue.
Note though that by the end of 2021, Xamarin will no longer be known as Xamarin but as .NET MAUI. Curious about the future of Xamarin and your products? Let us explain below.
.NET MAUI: what is it and what will happen to Xamarin?
In 2020, Microsoft announced that the next evolution of Xamarin will be .NET MAUI which stands for Multi-platform App UI. The reason for that is that Microsoft wants to bring mobile development to the .NET platform and .NET MAUI will be one of the core tools for that.
The main question that bothers anyone working with Xamarin right now is whether Microsoft will stop Xamarin support? Yes, in 2022 Microsoft will stop supporting Xamarin. Note that in November 2021, when MAUI will be released, Xamarin will also be officially switched to it. Keep these dates in mind if you have an ongoing Xamarin project or plan to start one.
As for .NET MAUI and its functionality, it’s claimed to be more efficient than Xamarin and to have better performance. MAUI is said to have a simplified development process, IDE support, slim renderers, unification of libraries, and total support for hot reloads. With such functionality under its belt, .NET MAUI seems like a pretty exciting development tool to work with.
Xamarin: technology type
Xamarin is an open-source platform for cross-platform development. What’s awesome about Xamarin is that it allows developers to share almost 90% of the code across platforms. In this way, all business logic can be written in a single language (usually C#) while the UI part of the app will have a native feel and look.
Xamarin does not give its developers much flexibility in terms of choosing an IDE to use and the development is possible in Visual Studio and Raider only. However, this is not really a drawback as the tools in the Visual Studio can significantly boost the development speed due to included project templates for Xamarin development.
Some of the most interesting Xamarin features:
Binding for underlying SDKs: Xamarin has complete bindings for almost all underlying SDKs in iOS and Android.
Direct invoking of Objective-C, C++, Java, C libraries: enables to use third-party code.
.NET BCL: Xamarin uses a good Base Class Library that has a variety of powerful features.
Compilation: Xamarin enables efficient compilation of source code into native code due to Xamarin.iOS and Xamarin.Android.
Xamarin.Forms vs Xamarin Native
When talking about Xamarin, it’s essential to mention Xamarin.Forms - another product by Microsoft that’s different from Xamarin Native.
We already said that Xamarin is an open-source platform for cross-platform development that allows developers to share the “backend” code across platforms while UI elements are written in the native language. Xamarin.Forms takes it a step further and allows to share not only the “backend” but the UI code too - how cool is that?
Of course, the concept of Xamarin.Forms sounds incredibly appealing and seemingly easier than the traditional Xamarin one. However, there are some things to keep in mind:
Xamarin.Forms is not recommended to develop apps with complex animations and rich UI;
Watch out for platform-specific components and how well Xamarin.Forms can realize them;
Xamarin.Forms apps are much heavier compared to Xamarin Native ones.
On the other hand, Xamarin.Forms is a great tool for developing MVPs or apps on a limited budget. As well, Xamarin.Forms allows nearly 100% of code sharing which is quite an impressive advantage too.
As for Xamarin Native, it allows achieving the speed of applications compared to one of native mobile apps as it calls Android and iOS APIs directly. Xamarin Native also removes code duplication as Android and iOS apps can use a common business logic library.
The use of Xamarin: most common cases
When we talk about Xamarin and its use cases, the first thing that comes to mind is mobile cross-platform development. However, the nature of Xamarin makes it more suitable for certain types of apps that we will now discuss below.
Apps for an existing .NET-based solution
Since Xamarin is built around .NET, it’s natural that it’s the best tool to build applications for existing .NET products. By doing so, developers can even share the logic with both the server and the mobile parts of the application. This, in turn, will speed up the development process and will facilitate it significantly.
Xamarin is suitable not only for building mobile but also desktop applications for Windows and macOS. This is possible by using Xamarin.Forms that has support for both Windows and macOS and thus enables developers to build feature-rich and highly functional apps for any platform of choice.
Xamarin Pros and Cons
As mentioned above, Xamarin is not as popular as other cross-platform tools but it’s still being used by some of the biggest brands out there. Hence, it’s important to explain its pros and cons so you can better understand what makes it the top pick and what puts it aside.
Xamarin is a framework whose main purpose is to bring .NET to different platforms and bring different platforms (i.e. their APIs) to .NET. This distinguishes Xamarin from other cross-platform frameworks: Xamarin is not just about how to create UI for all platforms from a single code base, Xamarin is about a full union of .NET and different platforms. This gives Xamarin a lot of power and flexibility because .NET is a very rich and mature framework. IO, networking, cryptography, database access, built-in data types, and algorithms - the list of features that .NET provides out of the box would take much more than any blog can allow encompassing. But with Xamarin, .NET is enriched even further due to bindings to platform libraries.
Unfortunately, such a variety of tools leads to the main Xamarin’s drawback: Xamarin is quite complex, especially Xamarin.Forms. It is quite common to meet hiccups here and there while developing a large real-life application because different platforms behave slightly differently while being united in a single .NET.
I would recommend using Xamarin when the app’s complexity goes far beyond the UI and when the gains from the rich .NET tools outweigh the efforts spent on small hiccups here and there. I wouldn’t recommend Xamarin for apps with simple logic and complex UIs though.
Anton, Full Stack Developer
Xamarin is an efficient tool that is about to see some significant changes upon the launch of .NET MAUI. However, this change should not discourage you from using Xamarin, especially if your team specializes in working with .NET. You’ll have plenty of time to wrap your head around it and to prepare for the switch to MAUI in the future.
At SoftTeco, we are actively using Xamarin and for now, it never let down our expectations so it’s definitely worth a try. And in our next article, we’ll talk about Flutter - so sign up for the newsletter and stay updated!