With today’s development tools there are many other options for mobile application development. There are two categories for mobile application development, native and hybrid. Hybrid applications allow for HTML and native code to coexist for easier development. A very common debate in recent days is whether or not to use Xamarin (native) or Ionic (hybrid). Both can deliver valuable products but vary in quality and performance. It really depends on what type of application you are building. Hybrid mobile development is certainly a viable option, but today we are going to take a deeper dive into Xamarin and its uses.
So, what is Xamarin?
Xamarin, now owned by Microsoft, is a cross-platform development tool used for mobile application development that allows developers to share most of their code across major platforms. Xamarin, founded in 2011 by the developers of Mono, Mono for Android and MonoTouch, was purchased by Microsoft in February of 2016. At Microsoft Build 2016, Microsoft announced that they will open-source the Xamarin SDK in future builds of Microsoft Visual Studio. Visual Studio Enterprise developers also get the Xamarin enterprise features free of charge. According to Xamarin, as of April 2017, over 1.4 million developers in 120 countries were using Xamarin products.
Xamarin uses a single language, C#, to create apps for the iOS, Android and Microsoft Universal Windows mobile platforms. Xamarin is natively compiled for each platform, providing excellent performance applications that include a native look and feel on iOS, Android and Microsoft mobile devices.
C# is one of the .NET framework languages that has many useful .NET features including (but not limited to) Linq, Lambda expressions, Asynchronous calls and many importable libraries for pre-developed functionality.
There are three platforms within Xamarin: Xamarin.iOS, Xamarin.Android and Xamarin.UWP. When compiling for iOS, the source is compiled directly to native ARM assembly code, which requires an actual Apple Mac for the compilation. For Android, the source is compiled to an intermediate language that is then pushed to native assembly code at runtime. In both cases, the process is automatic and designed to handle memory allocation, garbage collection, native device interfaces and platform interaction. For Universal Windows Platform (UWP), code is pre-compiled with .NET Native. The .NET Native toolchain compiles the managed intermediate language binaries into native binaries.
Xamarin does have some drawbacks, but overall the benefits outweigh those due to the fact you can share most of your code and design across all the major mobile platforms.
Pros and Cons of Xamarin
First, the Pros:
- One of the most beneficial pros is one technology stack for coding across the mobile platforms. You can reuse more than 95% of your source code which allows for faster development. You don’t have to switch environments to do the development. You no longer are required to use Xamarin Studio now that it is all integrated into Microsoft Visual Studio.
- The second most beneficial pro is that you get native performance, or as close to it as you can without having to write native code. There have been many performance metrics compiled showing that Xamarin performs very comparable to that of Objective C or Swift and Java for their respective platforms. In addition to the development, Xamarin in Microsoft Visual Studio provides features for testing and performance analytics. You can even do automated testing utilizing Xamarin Test Cloud and Xamarin Test Recorder.
- The user experience is native. Xamarin utilizes the mobile device design elements within the compiled code. For example, when developing a form for data capture, the design of the text boxes, radio buttons, select lists, dropdowns, grids and many other input controls will appear as they should on that device. The Xamarin cross-platform development environment does not force each platform to look identical to each other. This guarantees that an iOS user does not feel like they are all of a sudden using an Android application on their device or vice versa.
- Hardware support via APIs and plugins. Xamarin native application functionality addresses hardware compatibility issues via APIs and plugins. Xamarin also supports integration with native hardware libraries.
- Microsoft supported development tool. Now that Microsoft has purchased Xamarin, you get the support from Microsoft on what was originally an open source product. There are many support tools for Xamarin that include implementation documentation, training, video tutorials and feature release documentation.
Now, for the Cons:
- Xamarin is still a young product. Technically, it has only been around for six years. Previous versions were not as developed and required separate development tools from Microsoft Visual Studio. Also, when there are issues that require research, sometimes finding the answers seems like looking for a needle in a haystack. Try using Xamarin forums to find answers that others may have already encountered and always post your solution when you find it. The Xamarin development community is a relatively small compared to that of the iOS or Android, but it is growing quickly.
- Not a great environment for heavy graphic development. Building games or rich user interfaces with animations can be very challenging. There are not many plugins at the moment that are strong enough to make it a viable development platform for these types of applications.
- Application size can be larger than expected. Due to the nature of the shared code development and libraries utilized for the native code, the compiled size of the resulting code can be significantly larger than that of a natively developed application for iOS or Android.
- Third party libraries and tools can have compatibility issues. When utilizing certain third party libraries, pay attention to the details. Many will outline specifics like support hardware, platform versioning and other specific limitations.
Other Mobile Development Options: Native iOS, Native Android or Hybrid Development
There are many pros/cons about which development option should be used when developing mobile applications. Here are some of the comparisons being made in the marketplace and how they measure up:
Xamarin | Native | Hybrid | |
Technology Stack | One stack, single code base (C#, .NET framework, native libraries) | Different stacks for each platform (iOS, Android, UWP) | One stack, single code base (JavaScript, HTML5, CSS) |
Code share | Up to 95% or more | Different code base for each platform | Up to 95% or more |
User Interface/Experience | Native look and feel for each platform. Very minor differences if any. | Absolute native look and feel | Close to native, but enough difference to know that something is different |
Performance | Close to native | Native | Poor when performing complex tasks due to non-compiled code |
Hardware compatibility | Utilizing platform specific APIs and native libraries provides high compatibility | Native code base has complete support for system compatibility out of the box | Utilizing platform-specific APIs and native libraries provides compatibility but there are some risks due to the quality of these tools |
Time to market | Xamarin.Forms provides the fastest time to market due to its limited customization and code sharing. Xamarin.iOS & Xamarin.Android increases time to market due to custom code requirements. | When building individually for iOS or Android, comparative to Xamarin.Forms. However, when having to build for multiple platforms, time to market will depend on how many developers are working simultaneously | Hybrid is probably the fastest time to market due to single code base and limited customization. It is also a great tool for prototyping or proof of concept projects. |
Security | Since the code is compiled to the native platform, internal security is strong. | Since the code is compiled to the native platform, internal security is strong. | Since the code sits in the HTML5/JavaScript realm, hacking or modification can occur much easier and can allow insight into poorly implemented processes |
There are many discussions on which tool is the right fit. This really depends on how you plan to develop, support and grow your application. If you need high performance, high compatibility and graphic intensive mobile applications, native will most likely be your choice. If the graphics can be less intensive, Xamarin is a solid choice. If you want to go the fastest route and are willing to sacrifice on performance and some compatibility, then hybrid is a good option.
Wrapping it up
Xamarin is a great option for the following reasons:
- Code sharing
- Native user experience
- Performance
- Hardware Compatibility
- Time to market
- Security
- Microsoft technology stack
Other developers may weigh these differently, resulting in the choice of another option when it comes to building a mobile app. That is the great thing about having options, we can build based on what works best for the developers and the particular project.