Xamarin – Microsoft’s New Cross-Platform Interface

7 min read

About us: 

As a Microsoft Gold Partner, SoHo Dragon loves to highlight Microsoft products/services that we feel are cutting edge, innovative, and state of the art- just like us. Although we are most notable for our SharePoint expertise, we also provide services in BI, Staff Augmentation, and other hosted solutions. We like to think we are pioneers in the digital workplace!

Xamarin – What is it? 

Xamarin is a product now owned by Microsoft.  The product was developed by engineers who created MonoMono for Android and MonoTouch that are cross-platform implementations of the Common Language Infrastructure (CLI) and Common Language Specifications (often called Microsoft .NET).

 

New call-to-action

With a C#-shared codebase, .Net developers can use Xamarin tools to write native Android, iOS, and Windows apps with native user interfaces and share code across multiple platforms all from Visual Studio

Xamarin Evolve 2016: Keynote

So what does this mean?  The Visual Studio developers can now develop smartphone apps…  Oh Yeah!

The Skinny 

Xamarin has three basic sets of .NET libraries:

  • – Xamarin.Mac, which has evolved from the MonoMac project.
  • – Xamarin.iOS, which evolved from MonoTouch.
  • – Xamarin.Android, which evolved from Mono for Android or (more informally) MonoDroid.

Together these libraries are known as the Xamarin platform and consist of .NET versions of the native Mac, IOS, and Android APIs, any geek using these libraries can write applications in C# and to target the native APIs of these three platforms with a code once, deploy anywhere approach.

But wait there’s more. There’s access to the .NET Framework class library.

Use modern C# language to write code that can work cross platform:

  • – For iOS, C# is ahead of time compiled to ARM assembly language.
  • – For Android, C# is compiled to IL and packaged with MonoVM + JIT’ing
  • – For Windows, C# is compiled to IL and executed by the built-in runtime and does not require Xamarin.

References for a more detailed introduction to go Cross Platform with Xamarin:

https://channel9.msdn.com/Events/Build/2016/B836
https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Cross-Platform-Development-With-Xamarin

And why should a Visual Studio Developer care? 

  • – Often mobile app development involves a steep learning curve for a Visual Studio developer like learn programming languages such as Java for Android and Objective C or Swift for iOS, platform SDKs like Android SDK and iOS SDK, and IDEs like Android Studio and Xcode and also Mac OS if you developing for iOS.
  • – If you know .Net/C# which is common amongst  Visual Studio developers, then you can straight away start developing mobile apps writing code in C#.
  • – As now Microsoft owns Xamarin, so it is available for every visual studio edition including the community edition which is free for individual developers, education, and research. So visual studio developers feel at home to develop cross-platform mobile apps using Xamarin. Developers don’t need to learn a new IDE in order to develop mobile apps.

How easy is it to learn? 

C# and .NET developers will be amazed due to the following reasons, on how easy it is to develop cross-platform mobile apps.

  • – .NET developers get the opportunity to reach, besides Windows, the major mobile platforms: iOS and Android.
  • – They don’t have to learn the new programming language and a new IDE
  • – Write less code as the backend of the code can be shared across platforms
  • – Use the Windows APIs such as System.Net, System.IO, System. Linq, System.Xml, System.Data and more which C# .Net developers would have been using since long in their .Net applications

If you are not a .net developer, then also you will spend less time in learning, as compared to learning different SDKs and programming languages Java for Android and Swift or Objective C for iOS. For Xamarin you will be required to learn only C# and common SDK and standard .Net classes across all three platforms.

  • – Use MVC (Model View Controller) or MVVM (Model View ViewModel) design pattern, to develop your application’s User Interface which is widely used across all programming languages which separate your backend and business logic code from UI code.
  • – Share your code across three platforms, so you have to write unit tests only once, fix non UI bugs on three platforms at once, reuse code from your old desktop apps or websites. So, in summary, there is less code to maintain, which reduces time, effort and cost.

Links: Xamarin for Absolute Beginners

What’s tricky about it? 

Xamarin has an operational overhead as app size can grow proportionally as code uses more and more APIs. This is due to way .Net assemblies are linked as native code, into apps. This affects the download time, startup time of the app and amount of storage space that the app uses on your devices. So keep a watch on the APIs you keeping adding to project which will increase the size of the app, the example below:

  • – I wrote a sample app to get check the connectivity of the phone to the internet and if it’s connected to the internet then the app displays the public IP to the user. So this app did not have code more than 100 lines, and it used few libraries such as HTTPClient, Xamarin Forms, and HTMLPack, though the app size was around 26 MB for Android. That’s quite large for a tiny sample app. Though there are some workarounds to reduce the size of the app which may help to reduce the app size.
  • – Shared code can also be written for UI using Xamarin forms, but this has limited controls, so if you want to write an app with much-customized UI, then, in the end, you will end writing platform-specific code, so most of the UI code will still be platform-specific, examples below:
  • – We wanted to make a horizontal tiled UI in Xamarin forms app with which we could use Data Binding and MVVM, but there aren’t any controls available in Xamarin Forms to do that kind of UI. We had developed horizontal Tiled UI in Windows Universal Apps(UWP) using a GridView control which is not available in Xamarin Forms. Xamarin Forms only has ListView control in which items can go vertical and it’s like a list not tiles.
  • – We wanted custom interactive popups, with our data and inputs and buttons from which user can edit and save data, but those popup controls are not available in Xamarin Forms. Xamarin Forms only has alert functionality for a popup with which we can show informational messages to users. So we in order to implement custom interactive popups, we ended up writing platform-specific code for Android, iOS, and UWP.

References: https://gist.github.com/jgold6/a1e60e0bb24ccdd2b2b8

https://developer.xamarin.com/guides/android/advanced_topics/application_package_sizes/

https://montemagno.com/how-to-keep-your-android-app-size-down/

The Good 

  • Less maintenance of code due to shared code, hence fewer bugs.
  • Robust C# language, allows you to use a familiar syntax and sophisticated features like Generics, Linq and async/await/Task.
  • Faster time to market as compared to developing native apps for each platform. For Xamarin at least backend and application logic code can be shared.
  • Substantially less learning curve for companies who work mainly on .net platform.
  • Though the code you write is not native, user experience that Xamarin provides is native, so it provides platform-specific look and feels that Android and iOS users are accustomed to.
  • Large community support as Microsoft owns Xamarin, future support will also be good.
  • Test your apps using Xamarin Test Cloud which provides an automative way of UI Acceptance Testing of mobile applications in the cloud across a hundred different devices.

The Bad

  • UI code is still not shared though it provides Xamarin Forms framework which allows us to write shared UI code, is not robust to allow us to write attractive common UI code. Furthermore, Xamarin Forms is a package that runs on top of the Xamarin platform, so it will affect the performance of an app if the app is huge.
  • If you are certain to develop a mobile app for one specific platform, then native app development will be a better option.
  • You still require MAC to compile the apps for iOS.

The Ugly 

  • Size of app increase as you keep on adding more and more APIs to the code.
  • There is overhead on the download time and startup time of the app, due to the way linking of codes between .net framework and target application platform.
  • It does not support the sharing of code outside .Net environment e.g. Xamarin code cannot be used for native HTML 5 apps.

SoHo Dragon’s Recommendations: 

The Dragon Developers’ do not recommend using Xamarin for customer-facing application as it will require attractive and robust UI, using Xamarin here will not be helpful as you will end up writing platform-specific code. We recommend Xamarin to be used to develop a cross-platform line of business enterprise apps where there is significant business logic.
Want to decide whether or not to use Xamarin Forms then refer this: http://cdn1.xamarin.com/Architecture%20Selector.pdf

Recent Posts