In this article we will learn about Introduction to Xamarin. Xamarin is a framework to develop a cross-platform mobile application using the C#. Please read my all .NET core articles in this link.
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 enables developers to share an average of 90% of their application across platforms. This 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.
Xamarin offers 5 basic solution types:
- Xamarin.Forms (development for all platforms at once)
- Android application
- iOS application
- Android Wear application
- Watch OS application
Architecture of Xamarin
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.
History of Xamarin
Xamarin is a software company originated in 2011 and was recently acquired by Microsoft in the year,2016. It provides a developer with the whole range of tools which can be used for the development of cross-platform apps. Xamarin tools are easily available to download with Visual Studio.
Xamarin is Cross-platform
For mobile, tablet, and desktop applications, Xamarin provides a cross-platform development solution. Xamarin allows us to develop in C# with a class library and runtime which works across all many platforms including ios, Windows, and Android. Xamarin combines all the abilities of the native platforms and adds several powerful features of its own such are,
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.
Features of Xamarin
- Xamarin supports wearable devices such as Android Wear and Apple Watch. The functionalities of these wearable devices in their native application are included by downloading the simple plugins from the Xamarin Component Store.
- Popular Plugins are Cross-Platform, such as Text-to-speech and battery status. Platform-specific plugins too are available in Xamarin component store such as the Google Play billing support plugins.
- The Xamarin based cross-platform applications can easily be united to most of the popular backend platform such as Parse, Microsoft Azure, etc.
- Applications indexing in Xamarin allows those applications to be in search results, which are usually gets forgotten after a few uses from the users.
Pros of Xamarin
Fast App Development Cycle
The most crucial part of Xamarin App Development platform is that it contains the reusable code, 90% of which can be recycled for the development of apps on various platforms. The coding is based on C# language and .Net libraries. Since developers can reuse a great portion of original Xamarin codes for creating apps across different platforms. Due to simplified code sharing across different OS, Users have a shortened Product development lifecycle.
The solution for any application is native design. That is when Xamarin and its unique approach comes into existence. Xamarin Studio provides the advantage of Native UI, access to specific device features and most importantly, native performance. Sharing the code between the different platform is an easy task, which helps us to shorten the development lifecycle.
Shared App Logic
Apart from Native UI, the most powerful feature of Xamarin is shared, the app logic, which makes it is the most useful and most-usable cross-platform development tool. Application Logic underlying the UI layer like input validation, web service calls, database interactions, and backend enterprises integrations are coded once in C#. Developers can share 75% of the code across the various operating system. It saves the time to record in the applications, and there are fewer chances of the bugs.
Xamarin binds the same APIs and UI controls which are used to build the iOS, Android, and Mac apps in their respective platform-specific language. For Windows development, Xamarin with Microsoft Visual Studio offers windows phone and windows applications. Code is shared between iOS, Android, and Windows using the Portable Class Library (PCL) and appropriate application architecture. With Xamarin, support is always there. These unique binding technologies enable us to to provide the support for the new feature as soon as they come in the device’s operating system. Click on the respective platform links for their latest support packages for iOS 8 and Android L(with wearable support).
Xamarin Component Store
Xamarin believes in Collaboration and Component sharing. The developer chooses from the host free or paid component, which includes UI controls, cross-platform libraries, and third party web services to apps with just a few lines of code. The component store is built in the Xamarin Studio and Xamarin’s Visual Studio extensions.
Advantages of C#
C# is a simple, modern, general-purpose, type-safe, pure object-oriented programming language. Being the object-oriented, it is the modern version of C++, which allows the simple data types as objects. The type safety of C# helps to prevent the type errors. Its simplified syntax allows the use of pointers and headers. Namespace and reference operator is replaced by the period. C# is a great programming language for cross-platform development.
Cons of Xamarin
Large in file size
With consuming more time, Xamarin takes more space in storing the app file size because of the usage of the general use of Xamarin’s core libraries and functionality of the app stores with the wrong app file size. The size margin in the store may range from 3MB to 15MB.
Time-Consuming Nature of UI development
Time becomes an essential thing in UI development on the platform of Xamarin. Xamarin offers the facility to reuse the code across the target of the device platform. It is hard to create a portable version of the core UI. That is why Xamarin App Development experts thoroughly perform some portion of coding for an independent platform, which is a time-consuming process.
In this article we learnt about Introduction to Xamarin. The rich features and resulting benefits of all points towards the cross-platform native applications. In addition to the advantages of the Xamarin, it boasts up the ever-growing community of 70,000 plus developers who are continuously collaborating and enhancing the software.
Jayant TripathyCoder, Blogger, YouTuber
A passionate developer keep focus on learning and working on new technology.