20 years later, Microsoft's still hammerin' Xamarin: Bunch of improvements on the way for cross-platform coding toolset

Less fashionable than React Native, but a mature solution for .NET developers

Got Tips? 22 Reg comments
Xamarin Essentials provides a wrapper API for common tasks on multiple platforms
Xamarin Essentials provides a wrapper API for common tasks on multiple platforms – now including macOS

Microsoft continues to evolve its Xamarin technology for cross-platform coding with .NET, even though alternatives like React Native and Blazor are getting plenty of attention within the company.

The history of Xamarin goes back to the earliest days of .NET. In 2001, when C# and the .NET platform were still in preview, Miguel de Icaza (co-founder of the GNOME project) announced the open-source Mono project. Mono is an implementation of the .NET Framework for Linux, later supplemented by Mac and other platforms. In 2009, when Mono was owned by Novell, the team discovered demand for targeting Apple's iPhone with .NET code, and created MonoTouch, a C# wrapper for iPhone APIs.

In his announcement back in 2009, de Icaza noted that MonoTouch uses native iPhone controls. "It would not be a cross-platform API and it would tie developers to the iPhone platform, but it would also mean that applications would look and feel native, and developers would get closer to the iPhone," he said. In January 2011, de Icaza announced Mono for Android. By that time Novell had been acquired by Attachmate, and later in 2011 the Mono team left to form a new company called Xamarin. Aware of a mobile-shaped hole in its developer platform, Microsoft acquired Xamarin in 2016, and bundled the Xamarin tools with Visual Studio.

The Xamarin team insisted for years that a cross-platform GUI framework would be a mistake, preferring to share only non-visual code and to build a native GUI for each platform. Developer demand was there, though, and in 2014 the company delivered Xamarin Forms, which lets you define a basic GUI using a variant of XAML (different from that used by Microsoft's Windows Presentation Foundation or Silverlight), an XML language. Xamarin Forms still uses native controls. Take-up exceeded the company's expectations, since it turns out that the extra productivity from shared GUI code often outweighs any disadvantages.

Fast forward to 2020, and Xamarin remains the obvious path for developers with existing C# code or skills who now need to target iOS and Android. Xamarin can also target macOS and UWP (Universal Windows Platform). Earlier this week Microsoft held a virtual conference to update developers on what is happening with Xamarin.

The first thing to note is that Xamarin Forms (versus designing a native GUI separately for each platform) now seems to dominate – judging by its high profile in the virtual conference. In a well-received session, developer Steven Thewissen spoke about "building beautiful apps", observing that "Xamarin Forms has a bit of an image problem" thanks to its initial launch as something for simple data entry applications. The name is now a misnomer, he suggested. Thewissen explained how to use gradients, shadows and typography with Xamarin Forms, using either libraries like SkiaSharp, based on Google's Skia Graphics library, or the Xamarin Forms gradients API, which he said is "coming soon". Using Forms is best for cross-platform apps, he added, since other approaches cost "way more".

Another prominent topic was Xamarin Shell, a simplified XAML framework that lets you create a bare-bones application declaratively, to which you can add rich content as needed. Using Shell can improve performance as well as speeding development by providing essentials like flyouts, tabs and navigation. Dual-screen support is coming soon.

Xamarin Shell is a bare-bones, high-performance framework for the "shell" of an application

Xamarin Shell is a bare-bones, high-performance framework for the 'shell' of an application

Productivity is also improved by using Xamarin Essentials, which provides a cross-platform API to access hardware and operating system features such as the clipboard, file operations, accelerometer, network, geolocation, launching other applications, sending SMS messages, or even converting text to speech. Version 1.5, just released, adds OAuth authentication. Version 1.6, in preparation, will add macOS support (currently it is just Android, iOS and UWP), as well as file pickers and access to contacts and calendars.

Rodney Littles II, a senior software engineer in Texas, presented ReactiveUI, for which he is a maintainer. The library is exactly what its name implies: a library that enables reactive programming for a user interface. Using this approach improves code readability as well as helping reusability of code and remaining understandable as applications become more complex, he said.

On the platform support side, support for Apple's Xcode 11.4 is out now and support for Android 11 will come with Visual Studio 2019 16.6 preview 2, we were told (the current preview is 16.6 preview 1). Visual Studio on Windows seems to be ahead of Visual Studio Mac for Android development, though the latter is more convenient for targeting iOS and essential for targeting macOS. AndroidX, the updated Android support libraries also known as Jetpack, are supported in Xamarin and there is an AndroidX migrator in preview which will assist with updating existing applications.

Developing for iOS on Windows has become easier, thanks to a feature called Xamarin Hot Restart now in preview. This only works with Xamarin Forms apps for iOS. It lets you debug your app on a connected iOS device, with the ability to make changes to the code and push them to the device without a full rebuild and deploy. The effect is that you can test and debug with just Windows and a device, rather than needing to use a connected Mac.

If .NET Core realises the goal of .NET on any platform for web and server applications then Xamarin does nearly the same for client applications. There are a few snags. On Windows, Xamarin can target UWP but not traditional Win32 applications, though there is preview support for WPF. There is also uncertainty over Xamarin Forms support for WinUI, which is in Microsoft's current thinking the future for Windows development. A GitHub issue on the topic is marked as "under consideration".

Love

Xamarin: Design an app for Windows, iOS and Android ... from one codebase?

READ MORE

The fact that Xamarin is cross-platform is, as ever, a mixed benefit. If you only want to target one platform, it is unlikely to be the best technology to use. Even if you are doing cross-platform, enthusiasm for Xamarin within Microsoft seems to vary, with the Windows team as likely to point you towards web technology or React Native. Cross-platform adds complexity, and Xamarin technology has at least its fair share of issues.

Developing for iOS and Android with Visual Studio for Mac 8.5

Developing for iOS and Android with Visual Studio for Mac 8.5

It is also worth noting, however, that Xamarin is now well established as a viable cross-platform solution and one that has been kept up to date with changes in iOS and Android, its primary targets. The Microsoft acquisition has paid off, with more code shared between Xamarin and .NET Core, and improved tooling in Visual Studio on both Windows and Mac (Visual Studio for Mac 8.5 has been just released). The platform is greatly improved from its early days, particularly with the success of Xamarin Forms in providing a viable cross-platform GUI framework. ®

Sponsored: Ransomware has gone nuclear

SUBSCRIBE TO OUR WEEKLY TECH NEWSLETTER


Biting the hand that feeds IT © 1998–2020