Xamarin lets you build native user interfaces for Android, iOS, and Universal Windows Platform from one shared C# codebase. It provides multiple cross-platform controls and layouts for rich user experiences.
What is Xamarin?
Xamarin is an open-source platform for building modern and performant applications for iOS, Android, and Windows with .NET. Xamarin is an abstraction layer that manages communication of shared code with underlying platform code. Xamarin runs in a managed environment that provides conveniences such as memory allocation and garbage collection.
Xamarin pattern allows developers to write all of their business logic in a single language (or reuse existing application code) but achieve native performance, look, and feel on each platform. Xamarin applications can be written on PC or Mac and compile into native application packages, such as an .apk file on Android, or an .ipa file on iOS.
The diagram shows the overall architecture of a cross-platform Xamarin application. Xamarin allows you to create native UI on each platform and write business logic in C# that is shared across platforms. In most cases, 80% of application code is sharable using Xamarin.
Xamarin is built on top of .NET, which automatically handles tasks such as memory allocation, garbage collection and interoperability with underlying platforms.
Xamarin combines the abilities of native platforms, while adding features that include:
- Complete binding for the underlying SDKs – Xamarin contains bindings for nearly the entire underlying platform SDKs in both iOS and Android. Additionally, these bindings are strongly-typed, which means that they’re easy to navigate and use, and provide robust compile-time type checking and during development. Strongly-typed bindings lead to fewer runtime errors and higher-quality applications.
- Objective-C, Java, C, and C++ Interop – Xamarin provides facilities for directly invoking Objective-C, Java, C, and C++ libraries, giving you the power to use a wide array of third party code. This functionality lets you use existing iOS and Android libraries written in Objective-C, Java, or C/C++. Additionally, Xamarin offers binding projects that allow you to bind native Objective-C and Java libraries using a declarative syntax.
- Modern language constructs – Xamarin applications are written in C#, a modern language that includes significant improvements over Objective-C and Java such as dynamic language features, functional constructs such as lambdas, LINQ, parallel programming, generics, and more.
- Robust Base Class Library (BCL) – Xamarin applications use the .NET BCL, a large collection of classes that have comprehensive and streamlined features such as powerful XML, Database, Serialization, IO, String, and Networking support, and more. Existing C# code can be compiled for use in an app, which provides access to thousands of libraries that add functionality beyond the BCL.
- Modern Integrated Development Environment (IDE) – Xamarin uses Visual Studio, a modern IDE that includes features such as code auto completion, a sophisticated project and solution management system, a comprehensive project template library, integrated source control, and more.
- Mobile cross-platform support – Xamarin offers sophisticated cross-platform support for the three major platforms of iOS, Android, and Windows. Applications can be written to share up to 90% of their code, and Xamarin.Essentials offers a unified API to access common resources across all three platforms. Shared code can significantly reduce both development costs and time to market for mobile developers.
Pros of Xamarin
- Xamarin uses a single language(codebase) C# to create apps, which actually makes it a superior option for building high-performance apps with native look and feel.
- Xamarin has two major products: Xamarin.iOS and Xamarin.Android. In case of iOS, the compilation of source code is done using ‘Ahead-of-Time Compilation’ whereas, in Android apps, the former is performed using the Just-in-Time Compilation approach. However, both of the cases are automated and efficiently handles issues regarding memory allocation, garbage collection, and platform interoperability by default.
- Xamarin uses C# augmented with .NET framework to create apps on all mobile platforms, 96% of the source code can be reused speeding up the development process. One can build all of the apps using Xamarin in Visual Studio which has now completely substituted Xamarin Studio. Besides, Xamarin also doesn’t require swapping between the development environments.
- Performance of a cross-platform app built using Xamarin is close to native. It’s accomplishment metrics can be compared to those of Java for Android and Objective-C or Swift for iOS app development. Moreover, constant refinements are also being made in Xamarin, to let it entirely be a facsimile of the native platform apps. Xamarin Test Cloud coupled with Xamarin Test Recorder tool allows a developer to run automated UI tests and check the performance related issues before the release but with an additional fee.
- There is simplified Maintenance and updates in Xamarin due to its cross-platform application. On applying changes or updates to the source code of the file, modifications would be reflected in both iOS and Android apps. But this works only for the applications using Xamarin.Forms or the business logic, shared code, .updates for Xamrion.iOS and Xamarin.Android apps.
Cons of Xamarin
- Xamarin provides slightly delayed support for the latest platform updates. Obviously, it’s impossible for the third party tools to immediately provide support for the latest iOS and Android release. Although Xamarin claims to provide the support for the latest version on the same-day of their release, there might have slight delays.
- It is undoubtful that the Xamarin community is much smaller than those of iOS and Android. So, it would be really hard to find an experienced Xamarin developer. Although, this is growing every day with the support of Microsoft. Considering the stats from various sources, Xamarin community accounts for only 10 percent of the global mobile development society. Even with this number of Engineers, Xamarin provides extensive support to them. The dedicated educational platform, Xamarin University provides resources and practical training to the newbies in this technology.
- Xamarin developers and consumers can use only the components provided by the platform and some .Net open source resources. But native development incorporates extensive use of open source technologies. Though Xamarin components provide thousands of custom UI controls, various charts, graphs, themes and others that can be included in the app with just a few clicks, the number is incomparable to open source libraries of Android and iOS.
- Even if Xamarin uses a single codebase C# for both the platforms, but the developer while using Xamarin.iOS and Xamarin. Android, still need to write some platform-specific layer of code. So, it requires basic knowledge of the native technologies such as Java/Kotlin for Android and Objective-C/Swift for iOS. However, this doesn’t apply to Xamarin.Forms.
- Xamarin is not suitable for Apps with Heavy Graphics as you can only share the logical code, but the UI code would mostly be platform specific which actually makes it worthless to create games, rich custom UI, or complex animations in Xamarin.
- Xamarin apps are comparatively larger than the native ones. Actually, Native apps account only for half of the size of the Xamarin apps. Maximum of the space is utilized by the associated libraries, content, Mono runtime, and Base Class Library(BCL) assemblies.
- There are compatibility issues while integrating third-party Libraries and Tools with the app built on Xamarin platform. Though there is a Xamarin component store, there might be situations when the developer needs a specific capability or integration within his own app that are not provided by the platform.