Speed up your time to market with Xamarin
Have you ever questioned what the best way is to develop an app for multiple platforms? Do you need to develop an app per platform? Not with Xamarin! In this blog I’ll cover the benefits of Xamarin and how Xamarin can speed up the time to market for your apps.
There are several strategies to go with when developing an app: native, hybrid or cross-platform. In the following paragraphs I’ll explain briefly the main differences between these three strategies for developing an app.
Native app development
The most common option is developing a native app. This means that for each platform (eg. Android, iOS and Windows Phone) you need to develop an app separately. This also means that you need to develop your app in different programming languages because each platform has its own runtime. Specific knowledge of each programming language is required and you also need to work with different integrated development environments (IDE’s for short), which most developers don’t really appreciate. If you want to develop an app for just one platform, this strategy is a solid option to go with as you will have a full native user interface and full access to the native API.
Hybrid app development
Cross-platform app development
The last strategy is to develop a cross-platform app. Developing a cross-platform app is similar to developing a hybrid app. The main difference is that cross-platform app development delivers full native apps. Which means that it has the look & feel and the performance of a native app. With Xamarin you have the ability to deliver full native apps for each platform in a single codebase (.NET) and with just one IDE (Visual Studio) without losing the ability of accessing the native API for each platform. This way of cross-platform development allows you to share your business, data, data access and service access layers. You only need to customize your application and UI layers per platform. With MvvmCross (a cross-platform MVVM framework) you are even able to share UI logic and platform-specific code. I’ll explain more about MvvmCross in my next blog. Xamarin allows you to share most of your code between the different platforms but also gives you the ability to write platform specific code when needed. This is all possible while developing in .NET.
Shared projects vs. Portable class libraries
Using a shared project is the simplest approach of sharing code that can be used by the specific platform projects. Also platform specific code is supported using compiler directives (eg. #if __ANDROID__ or #if WINDOWS_PHONE). Disadvantage of a shared project is that is has no ‘output’ assembly. The shared code is compiled in each platform specific assembly. You are unable to share your code as a separate DLL to other projects then the ones in your own solution.
Figure 1: Shared project architecture
When using a portable class library you need to select the platforms you want to target. This results in a target framework profile which defines which part of the .NET Framework can be used inside your portable class library. When you need to implement something platform specific, you can use dependency injection. This allows you to inject that class into your project and this will give you access to the platform specific code from any PCL referenced by all other projects. The platform specific code will be implemented in the different platform specific projects.
Figure 2: Portable class library architecture
Benefits of using a PCL over shared projects is that your code is more unit testable due to the use of dependency injection. Also your code has a better architecture as you don’t mix up platform specific code in your business code by using compiler directives.
Xamarin native vs. Xamarin.Forms
With these abilities you are able to share most of your code between the different platforms but Xamarin even takes it one step further with Xamarin.Forms! Xamarin.Forms is a cross-platform UI toolkit that allows you to easily create native user interface layouts that can be shared across the different mobile platforms. This allows you to create shared UI code by developing your UI in XAML but still get native controls on each specific platform.
Figure 3: Xamarin native vs. Xamarin.Forms architecture
The main difference with Xamarin native (also known as Xamarin.Android and Xamarin.iOS) is that the layouts are developed in XAML instead of the UI technique of the specific mobile platform. Where Android uses AXML layout files with Activities as the ‘code behind’, iOS uses XIB layout files with the MVC pattern and Windows Phone uses XAML layout files with the MVVM pattern as their specific UI technique. Both (Xamarin native and Xamarin.Forms) do result in a native app with native controls.
Using Xamarin.Forms speeds up your development, ideal for prototyping and proof of concepts, but it also lacks a little platform specific functionality. You are also not allowed to fully customize the presentation per platform but you will still need to satisfy the style guidelines from the Google Play Store and the Apple App Store. This is more difficult when the presentation is the same for each platform. For example: a return button is needed for an iOS app but an Android phone has a hardware button for this. Xamarin native allows you to develop apps that have highly polished designs, which can be (slightly) different per platform to satisfy the different style guidelines, but it also takes more code as you need to develop the UI layer separately for each specific platform.
When you want to develop an app for multiple platforms (eg. Android, iOS and Windows Phone) you don’t need specific programming skills for each platform with Xamarin.Forms. If you are using Xamarin native you’ll only need to develop the UI layer separately per platform. Xamarin allows you to develop a cross-platform app by just using .NET and Visual Studio. Also Xamarin gives you full access to the native API of each platform and delivers full native apps. This way you don’t have to develop an app for each specific platform and are you able to speed up your time to market with your app developed with Xamarin!
Last year we have organized a Mobile Hackathon at Suneco where 22 developers have been developing a cross-platform app with either Xamarin native or Xamarin.Forms in just 12 hours. This resulted in a solid foundation of Xamarin knowledge within Suneco. After the Mobile Hackathon we’ve started with a Xamarin project called GroupRater. This is a promising social app where you can create groups and subjects and group members can vote on each other. The project is now in the Google Play beta store. We are still working on the finishing touches of the iOS app.
If you want to know more about Xamarin or mobile development in general or if you want to know how we can boost your business with a mobile app: please don’t hesitate to contact us and we’ll be happy to be of any assistance to you!
Onze technische blogs zijn in het Engels. Dit doen wij omdat wij menen dat technische kennis van Sitecore, Sitefinity en mobile grensoverschrijdend moet zijn. Wij leren veel van buitenlandse developers, wij delen onze kennis ook graag met hen. Mochten er in de code fouten zitten of punten ter verbetering, dan gaan we graag het gesprek aan.
Need help with building your app? Read more about app development at Suneco and get in contact with us.