Today there are many options to choose from when building a mobile application. What’s clear is that if you do not support both iOS and Android at a minimum, you run the risk of alienating potential users. Many organizations have mitigated that risk by investing heavily in creating multiple teams that have different skills and use different tools to deliver applications targeted for the various mobile platforms. For some, that investment may seem like a duplication of effort and potentially presents an opportunity to consolidate and reduce costs. Again there are several options to consider when evaluating this opportunity but if your organization has a current investment in the .NET (Microsoft) framework using C#, Xamarin could be a solution that allows you to leverage that investment to extend the value your organization creates into the mobile space.
Xamarin, founded in 2011 by Miguel de Icaza and now owned by Microsoft, is an open source platform that allows developers to create native iOS, Android, and Windows applications using the .NET framework and C#. For organizations/teams that currently develop using the .NET framework, this is very familiar territory because Xamarin is fully integrated into Visual Studio and Visual Studio for Mac which are core development tools in this space. So if you are looking to leverage existing .NET/C# skills, the Xamarin story starts to become compelling; but there is more....
Developers have a myriad of options when creating software to solve problems. Without guidance and experience, they can get into trouble really quickly. Of all the guidance available (and there is plenty), there are two things that I consider paramount for success as a developer; 1 - Keep things simple, 2 - Don’t repeat yourself (DRY which contributes to #1). Code reuse should be a top priority when developing production software.
Because the Xamarin platform utilizes the .NET framework, there are some tools, cross platform capabilities, and code reuse strategies available that enhances the Xamarin story. For example, C# is used to create applications with the Xamarin platform and the language provides features that can be leveraged with intentional design to achieve code reuse. (i.e. class inheritance, generics, etc.) Also, the .NET framework supports Shared Projects, Portable Class Libraries (PCL), and .NET Standard Libraries. Placing core business logic in those project/libraries, allows them to be used in solutions for all .NET framework target platforms including those supported by Xamarin. For example, one could have core business calculations or operations in a Shared Project, PCL, or .NET Standard Library and reuse that code for windows, web, and Xamarin applications. Here is a quick break down of the features/options for the project/library types:
Shared Projects
|
Portable Class Libraries(PCL)
|
NET Standard Libraries
|
Allows code to exist in a common location that can be shared between target platforms |
Allows code to exist in a common location that can be shared between target platforms |
Allows code to exist in a common location that can be shared between target platforms |
Compiler directives are used to include/exclude platform-specific functionality located in the code |
PCL’s cannot contain any platform-specific code
PCL’s have a profile that describes which features are supported (the broader the profile, more selected platform targets, the smaller number of available features)
|
.NET Standard Libraries cannot contain any platform-specific code
.NET Standard Libraries have a larger number of available features than PCL’s
.NET Standard Libraries have a uniform API for all .NET platforms supported by the version of the library
|
During the build process, the code in the shared project is included in each platform target assemblies. (there is no output assembly for a shared project) |
PCL’s are referenced by other projects and there is an output assembly after the build |
.NET Standard Libraries are referenced by other projects and there is an output assembly after the build |
More Shared Project information |
More PCL information |
More .NET Standard information |
Microsoft released .NET Standard 2.0 in late 2017. In this release, the number of API’s supported increased by over 20,000 from the previous version (1.6) of the .NET Standard. This increase allows developers to place even more code into reusable libraries. The .NET Standard 2.0 is supported by the following .NET implementations:
As you can see by the list, if your goal is maximum code reuse and your platform targets are supported by the .NET Standard 2.0, a .NET Standard 2.0 Library is where you should place all of your reusable code. For Xamarin, having code reuse central to your software architecture design goal allows you to deliver your mobile application faster to multiple platforms, but there is more...
What if you could take code reuse to the user interface? Well, you can with Xamarin Forms. Xamarin Forms allows developers to build native user interfaces for iOS, Android, and Windows using C# and XAML. Developers use abstractions of user interface controls to construct the user interface and at compile time those abstractions are converted to native user interface elements. By connecting a Xamarin Forms user interface with shared backend code, developers can build a fully native iOS, Android, and Windows application from a single code base and depending on the application and technical design, can achieve over 96% code reuse.
Until now we have covered all the advantages to using Xamarin for cross platform mobile development but what are the disadvantages? I have been using Xamarin for about a year. My largest hurdle has been learning about developing for the target platforms and their requirements. This is not a disadvantage of Xamarin but a entry cost to anyone new to mobile development and selecting any tool would require paying this cost. So, I would say that Xamarin can be used for most mobile applications. Unless your application requires use of specific platform features or special hardware, Xamarin is real compelling option for delivering mobile applications on multiple platforms and a potential cost saver if your organization/team already has .NET framework and C# skills.
Keep Right’in Code!
Richard