Cross-Platform Mobile Development with Xamarin
Date: Friday, April 6, 2018
In my last post, I wrote about different approaches to mobile development and why cross-platform development should be a preferred approach for those who want their apps to reach the biggest audience. This time I will talk about Xamarin Platform, my tool of choice for mobile development.
Xamarin Platform provides tools that help with the development of cross-platform mobile applications with all the native features while sharing a common codebase. Xamarin makes it possible to develop native applications for iOS, Android and Windows Phone, using the C# programming language. It also includes app store delivery, performance testing and monitoring, and allows you to test your app on over 2000 real devices in the Xamarin Test Cloud.
One code to rule them all
A beauty of Xamarin lays in its code reuse. It allows for the building of apps with native user interfaces and shares an average of 75% of code across multiple platforms. If you want to go truly cross-platform, it is possible to use the Xamarin.Forms API to build one user interface to be shared across all platforms and reuse nearly 100% of the application code. With a thoughtful design, you can get the most of the code sharing benefits, by writing your business logic and data storage in a shared codebase, and still present native UIs on each platform.
Native user experience
When we hear the term “cross-platform development”, we can easily imagine an app with the most common feature-set and a generic user interface that really does not look nice on any of the platforms. However, Xamarin approaches this concept differently. If you want your app to have a truly native user experience, you can build its user interface separately for each platform and use the shared code only for the business logic of your app. You can access all of the platform-specific functionality from C# code and create apps that look and behave like the ones created with native languages.
How does it work?
Xamarin applications are built upon the .NET Base Class Library (BCL), which is a collection of classes used to support features such as XML, Database, IO, String or Networking. This subset of the .NET BCL is known as Xamarin Mobile Profile and it has been developed specifically for mobile applications. For iOS development, it has been packaged into the MonoTouch library and for Android into the Mono.Android library. Additionally, to the BCL, these libraries also contains wrappers to use with iOS and Android SDKs to enable access to underlying APIs directly from the C# code. The code is compiled into an Application Package, either with an ‘.app’ or ‘.apk’ extension, for iOS and Android respectively. These files are identical to the ones created with platform’s native development kit and can be deployed in the same way as native apps.
Mobile development for .NET developers
With Xamarin it is possible to adopt tools and knowledge of standard programming languages for mobile development. Xamarin is based upon Mono .NET framework which is a cross-platform implementation of the Common Language Infrastructure. You can code in the familiar C# language and use familiar concepts like Generics, LINQ, and Parallel Programming from the .NET framework. Additionally, Xamarin is integrated with Microsoft Visual Studio, which allows developers who are familiar with Microsoft products to develop their apps in the well-known environment.
It is free
Xamarin was acquired by Microsoft in 2016 and became a part of the Microsoft development tools family. It is integrated within the Visual Studio IDE and you do not need to pay any additional license to use it.
You can start using Xamarin for free with Visual Studio Community version which is available to download from Microsoft website. You will need to use your Microsoft account to get a free version of Visual Studio. Follow these instructions to set up Xamarin and start building great apps.