Xamarin

Xamarin is a cross-platform application development framework. It allows you to develop a mobile app using C# and reuse most of the codebase across multiple platforms including Android, iOS and Windows. Among the advantages of Xamarin are native user interfaces, native API access, native performance and developer productivity.

Xamarin itself leverages .NET development platform that comes with C# language, its compilers, base libraries, editors and tools. Xamarin extends .NET so that developers can build mobile apps and target multiple platforms.

Discussion

  • When should I use Xamarin?

    There are many hybrid and cross-platform frameworks to develop apps across multiple platforms, but these require skills in JavaScript and are best suited for Web developers. For them, Apache Cordova is one possible framework but do keep in mind that this is a hybrid approach that will not give native performance.

    Where performance is desired along with faster time to market via multiple mobile platforms, Xamarin must be preferred. Xamarin is best suited for developers coming from .NET, C# or Java backgrounds.

    As a note, Xamarin should not be confused with .NET Core, though both are cross platform and open source. Xamarin is for cross-platform mobile (though it can be used for MacOS) whereas .NET Core is for creating cross-platform web apps, microservices, libraries and console apps that can run on Windows, Linus or MacOS.

  • Why should I use Xamarin?
    App logic is shared across platforms. Source: de la Torre 2016.
    App logic is shared across platforms. Source: de la Torre 2016.

    Xamarin helps to expedite native mobile app development targeting multiple platforms. It's been said that for informational apps, 85% of code can be reused across Android and iOS. For more intensive apps, code reuse of 50% is possible. This code reuse comes from using shared C# app logic across platforms.

    User interface code itself is not shared by Xamarin but that's where Xamarin.Forms comes in. Using Xamarin.Forms 96% code reuse has been reported.

    For developers, this means that you get to build native Android, iOS and Windows Phone apps concurrently without having to build them one after another or having multiple teams with multiple skillsets and tools.

    Xamarin.Android and Xamarin.iOS provide further customization possibilities for developers who are looking at tweaking the app's look and feel achieved with Xamarin.Forms. There are several other benefits like seamless API integration, easy collaboration and sharing, etc.

  • Could you describe some useful Xamarin-specific terms that developers should know?
    AOT compilation used in Xamarin.iOS. Source: Microsoft Docs 2017b.
    AOT compilation used in Xamarin.iOS. Source: Microsoft Docs 2017b.

    The term managed code refers to code that's managed by .NET Framework Common Language Runtime. In the case of Xamarin, this is the Mono Runtime. In contrast, native code is code that runs natively on the platform. Managed code could be in C# or F#. Java/Android code are native to Android; or Objective-C code is native to iOS/MAC.

    During compilation, C# or F# code is converted to Microsoft Intermediate Language (MSIL). In Android and Mac platforms, MSIL is compiled to native at runtime using just-in-time (JIT) compilation. In iOS, due to security restrictions, this is not allowed. Hence ahead-of-time (AOT) compilation is performed.

  • What's the architecture of Xamarin?
    Architecture of Xamarin.Android. Source: Microsoft Docs 2018a.
    Architecture of Xamarin.Android. Source: Microsoft Docs 2018a.

    Architecture is described in the documentation in three places:

    In general, C# code and .NET APIs sit on top of Mono runtime, which in turn sits on top of the OS kernel. Architecture allows for managed code to invoke native APIs via bindings. In Android, Managed Callable Wrappers (MCW) are used when managed code needs to invoke Android code; Android Callable Wrappers (ACW) are used when Android runtime needs to invoke managed code. There's also the Java Native Interface (JNI) for one-off use of unbound Java types and members.

  • How much does it cost to use Xamarin?

    Xamarin was initially available for a license. After it was acquired by Microsoft in 2016, it's now bundled with the Visual Studio suite of tools for free. While Visual Studio is not completely free, there is a Community Edition, which is free for eligible companies and developers.

    The .NET platform itself open source and Xamarin in part of it. This means there are no fees or licensing costs, even for commercial use.

  • What are the pre-requisites for Xamarin app development?

    To develop the app, one should have good programming expertise in C#, assuming that the RESTful APIs required for the application are already available. A Windows PC will be required for development on Android and Windows platforms. iOS development is done on Windows PC but to build the app, a Mac will be required to be connected in the same network as per Apple's requirements.

  • How does Xamarin compare against other cross-platform frameworks?

    Among the cross-platform mobile frameworks are React Native, Ionic 2, Flutter, NativeScript, and Xamarin. Ionic 2, React Native and NativeScript rely on web technologies (HTML/CSS/JavaScript/TypeScript). Ionic 2 can suffer from performance problems. While Ionic 2 uses WebView (basically HTML wrapped in a native app), React Native and NativeScript use native UI components. Ionic 2 can also allow access to native API but will require the use of Apache Cordova. Xamarin uses native UI components and offers good performance.

    For development, Xamarin lacks automatic restarting and hot/cold swapping. In this aspect, React Native is one of the easiest for developer productivity. All frameworks allow native code bindings but this process is easiest on Xamarin. Xamarin offers full one-to-one bindings to native libraries whereas in React Native or Ionic, support is partial and done via an abstraction layer.

    A blog post from AltexSoft compares the performance of Xamarin apps against native apps. It concludes that performance drop due to Xamarin is acceptable for most cases but the use of Xamarin.Forms is not recommended when apps are CPU intensive.

  • What are some criticisms of Xamarin?

    It's been said that Xamarin support for latest platform updates (iOS/Android) are usually delayed. While iOS and Android developers can tap into an active ecosystem plus use open source technologies, similar following is limited in Xamarin. Xamarin is also not suited for apps that are heavy for graphics, where code reuse will be limited. For that matter, Xamarin developers still need to learn platform-specific languages for the UI, unless they also adopt Xamarin.Forms for their apps.

    Xamarin apps are also larger in size when compared to equivalent native apps. This is because the app has to include the Mono runtime and associated components. A simple "hello world" Android app written in Xamarin requires about 16 MB.

  • Where can I learn more about Xamarin?

    Xamarin has excellent documentation and code samples at their website. Specific official resources from Microsoft include:

    There used to be Xamarin University to train and certify professional developers. Since June 2019, this is now part of Microsoft Learn platform.

Milestones

1999

Miguel de Icaza and Nat Friedman start Helix Code for GNOME desktop application development for the Linux platform. In 2001, this is renamed to Ximian, which is acquired in 2003 by Novell.

2000

Microsoft releases .NET Framework and Visual Studio .NET along with introducing a new language named C#.

2001

Mono project is launched for supporting .NET applications on non-Windows platforms. Open source and based on .NET Framework, Mono enables developers to build cross-platform applications.

May
2011

Xamarin as a company is incorporated with the idea of building commercial .NET offerings for iOS and Android. In July, Novell gives Xamarin the rights to use MonoTouch and Mono for Android.

2016

Microsoft acquires Xamarin and releases Xamarin as part of Visual Studio suite of tools.

Sample Code

  • <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"       
                       x:Class="HelloWorld.MainPage">
        <ContentPage.Padding>
            <OnPlatform x:TypeArguments="Thickness">
                <On Platform="iOS" Value="20, 40, 20, 20" />
                <On Platform="Android, UWP" Value="20" />
            </OnPlatform>
        </ContentPage.Padding>
        <StackLayout>
          <Label Text="Hello World" />
        </StackLayout>
    </ContentPage>
     

References

  1. AltexSoft. 2016. "The Good and The Bad of Xamarin Mobile Development." Blog, AltexSoft, January 28. Updated 2020-02-27. Accessed 2020-07-24.
  2. AltexSoft. 2017. "Performance Comparison: Xamarin.Forms, Xamarin.iOS, Xamarin.Android vs Android and iOS Native Applications." Blog, AltexSoft, August 22. Accessed 2018-08-21.
  3. Cogan, Adam. 2015. "Getting 96% Code Reuse with Xamarin Forms." January 14. Accessed 2018-08-21.
  4. Cruxlab. 2017. "Xamarin vs Ionic vs React Native: differences under the hood." Medium, September 20. Accessed 2018-08-21.
  5. Guthrie, Scott. 2016. "Microsoft to acquire Xamarin and empower more developers to build apps on any device." Official Microsoft Blog, February 24. Accessed 2018-06-24.
  6. Microsoft. 2020. "What is Xamarin?" .NET, Microsoft. Accessed 2020-07-24.
  7. Microsoft Docs. 2017a. "Xamarin.Mac architecture." Advanced Concepts and Internals, Xamarin.Mac, April 12. Accessed 2018-08-21.
  8. Microsoft Docs. 2017b. "iOS App Architecture." API Design, Xamarin.iOS, March 21. Accessed 2018-08-21.
  9. Microsoft Docs. 2018a. "Architecture." Advanced Concepts and Internals, Xamarin.Android, April 25. Accessed 2018-08-21.
  10. Microsoft Docs. 2018b. "Working With JNI." Java Integration, Xamarin.Android, March 09. Accessed 2018-08-21.
  11. Microsoft Docs. 2019. "System requirements." Xamarin, Microsoft Docs, October 16. Accessed 2020-07-24.
  12. Mono Project. 2005. "Mailpost:earlystory." Archived from October 2003, November 03. Accessed 2018-08-21.
  13. Mono Project Docs. 2018. "About Mono." June 20. Accessed 2018-08-21.
  14. Montemagno, James. 2015. "Code reuse using Xamarin of 50-85% gets Apps faster to market." Interview, Blog, StreetHawk, April 15. Accessed 2018-08-21.
  15. Perception System. 2017. "9 Reasons to choose Xamarin for Mobile App development." Accessed 2018-06-24.
  16. Strikingly. 2018. "The Legends of .NET." Accessed 2018-08-21.
  17. Ung, Karina. 2019. "The Next Evolution of Xamarin Training: Microsoft Learn." Blog, Microsoft, May 6. Accessed 2020-07-24.
  18. Zia, Danyal. 2017. "Ionic 2 vs ReactNative vs NativeScript." Blog, DiscoverSDK, February 02. Accessed 2018-08-21.
  19. de Icaza, Miguel. 2011. "Announcing Xamarin." Blog, May 16. Accessed 2018-06-12.
  20. de la Torre, Cesar. 2016. ".NET Core, .NET Framework, Xamarin – The WHAT and WHEN to use it." Microsoft MSDN Blog, June 27. Accessed 2018-08-21.

Further Reading

  1. Xamarin. 2017. "Intro to Xamarin for Visual Studio: Native iOS, Android, and Windows Apps in C#." YouTube, March 2. Accessed 2018-06-24.
  2. Microsoft Virtual Academy - Xamarin courses
  3. Pluralsight - Beginning Mobile Development with Xamarin

Article Stats

Author-wise Stats for Article Edits

Author
No. of Edits
No. of Chats
DevCoins
6
4
1741
8
0
745
1261
Words
40
Likes
11K
Hits

Cite As

Devopedia. 2020. "Xamarin." Version 14, July 24. Accessed 2023-11-12. https://devopedia.org/xamarin
Contributed by
2 authors


Last updated on
2020-07-24 09:56:54
  • Types of Mobile Apps
  • C#
  • Microsoft Intermediate Language
  • Ahead-of-Time Compilation
  • Android App Development
  • iOS App Development