Xamarin
- Summary
-
Discussion
- When should I use Xamarin?
- Why should I use Xamarin?
- Could you describe some useful Xamarin-specific terms that developers should know?
- What's the architecture of Xamarin?
- How much does it cost to use Xamarin?
- What are the pre-requisites for Xamarin app development?
- How does Xamarin compare against other cross-platform frameworks?
- What are some criticisms of Xamarin?
- Where can I learn more about Xamarin?
- Milestones
- Sample Code
- References
- Further Reading
- Article Stats
- Cite As
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? 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? 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 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:
- Documentation
- Courses, tutorials and videos
- Community forums
- The Xamarin Show on MSDN
- Xamarin tutorials on Microsoft Learn
- Visual Studio tools for Xamarin
There used to be Xamarin University to train and certify professional developers. Since June 2019, this is now part of Microsoft Learn platform.
Milestones
2011
Sample Code
References
- AltexSoft. 2016. "The Good and The Bad of Xamarin Mobile Development." Blog, AltexSoft, January 28. Updated 2020-02-27. Accessed 2020-07-24.
- AltexSoft. 2017. "Performance Comparison: Xamarin.Forms, Xamarin.iOS, Xamarin.Android vs Android and iOS Native Applications." Blog, AltexSoft, August 22. Accessed 2018-08-21.
- Cogan, Adam. 2015. "Getting 96% Code Reuse with Xamarin Forms." January 14. Accessed 2018-08-21.
- Cruxlab. 2017. "Xamarin vs Ionic vs React Native: differences under the hood." Medium, September 20. Accessed 2018-08-21.
- 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.
- Microsoft. 2020. "What is Xamarin?" .NET, Microsoft. Accessed 2020-07-24.
- Microsoft Docs. 2017a. "Xamarin.Mac architecture." Advanced Concepts and Internals, Xamarin.Mac, April 12. Accessed 2018-08-21.
- Microsoft Docs. 2017b. "iOS App Architecture." API Design, Xamarin.iOS, March 21. Accessed 2018-08-21.
- Microsoft Docs. 2018a. "Architecture." Advanced Concepts and Internals, Xamarin.Android, April 25. Accessed 2018-08-21.
- Microsoft Docs. 2018b. "Working With JNI." Java Integration, Xamarin.Android, March 09. Accessed 2018-08-21.
- Microsoft Docs. 2019. "System requirements." Xamarin, Microsoft Docs, October 16. Accessed 2020-07-24.
- Mono Project. 2005. "Mailpost:earlystory." Archived from October 2003, November 03. Accessed 2018-08-21.
- Mono Project Docs. 2018. "About Mono." June 20. Accessed 2018-08-21.
- Montemagno, James. 2015. "Code reuse using Xamarin of 50-85% gets Apps faster to market." Interview, Blog, StreetHawk, April 15. Accessed 2018-08-21.
- Perception System. 2017. "9 Reasons to choose Xamarin for Mobile App development." Accessed 2018-06-24.
- Strikingly. 2018. "The Legends of .NET." Accessed 2018-08-21.
- Ung, Karina. 2019. "The Next Evolution of Xamarin Training: Microsoft Learn." Blog, Microsoft, May 6. Accessed 2020-07-24.
- Zia, Danyal. 2017. "Ionic 2 vs ReactNative vs NativeScript." Blog, DiscoverSDK, February 02. Accessed 2018-08-21.
- de Icaza, Miguel. 2011. "Announcing Xamarin." Blog, May 16. Accessed 2018-06-12.
- 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
Article Stats
Cite As
See Also
- Types of Mobile Apps
- C#
- Microsoft Intermediate Language
- Ahead-of-Time Compilation
- Android App Development
- iOS App Development