Xamarin: Design an app for Windows, iOS and Android ... from one codebase?
With my reputation?
Perhaps the most striking feature of Microsoft's Build developer conference in April was the crowd that gathered to hear Xamarin's Mac-toting Miguel de Icaza talk about mobile apps – meaning, of course, his company's tools for targeting iOS and Android with C#, the premier language of Microsoft .NET.
The session was so popular it had to be moved to the main keynote hall, and Microsoft's willingness to do this shows the extent of its new-found love for third-party devices, forced upon it by the small market share won so far by Windows Phone or Windows 8 tablets.
Xamarin has now released version 3 of its cross-platform development suite. There are some big new features. The first is a visual designer for Apple iOS, which runs in either Microsoft's Visual Studio or in the dedicated IDE, Xamarin Studio. Visual Studio runs only on Windows (other than via emulation), whereas Xamarin Studio is cross-platform on Windows and Mac.
The remarkable aspect of the iOS designer in Visual Studio, which is for Storyboard layouts, is that the controls are rendered on a Mac not on Windows. It is not possible to develop native code for iOS without using a Mac to compile and build, because Apple does not support any other platform, so when you start an iOS project in Visual Studio you are prompted to pair with a Mac. In my tests I used a Mac Mini on the local network. Since the Mac is available, Xamarin's Visual Studio designer uses it to render the controls. Xamarin CEO and co-founder Nat Friedman explains:
You're not seeing a simulation of what the UI will look like, we're using the underlying iOS framework to render everything so what you see is pixel-perfect. Because we are paired with a Mac, we can go out to that Mac and have it do the rendering, and bring back the rendered version directly into Visual Studio. We are running parts of the iOS Simulator subsystem on the Mac in order to give you this design canvas.
Another consequence of this design decision is that the designer can render custom controls, rather than showing them as blank rectangles.
The next big feature, which is entirely separate, is a new cross-platform graphical user interface (GUI) framework called Xamarin Forms, which runs on iOS (6.1 or higher), Android (4.0 or higher) and Windows Phone 8. Xamarin forms is actually an implementation of Microsoft's XAML UI language, though much cut-down from what is available for Windows. It has a set of around 40 controls and layouts. A key feature is that it wraps native controls, rather than drawing its own.
"We don't have a single line of drawing code in Xamarin forms. It doesn't do any custom drawing at all," says Friedman.
Forms is an about-face for Xamarin, which has hitherto argued that you can only get high-quality mobile apps by creating a dedicated UI for each platform. Why the change of mind? Apparently some customers baulked at the prospect of designing a UI separately for each operating system, especially with internal apps where the niceties of design excellence may be less important.
"It really came up for us in certain classes of enterprise apps, where people were building an internal tool with a large number of screens, and they value productivity very highly," Friedman told me. "With the mix and match approach, where you can mix in native code at any point, we think we've got the right compromise. And we're not forcing Xamarin forms on you, this is just an option."
Forms is now released in version 1.0, but this is early days and there may be "a few rough edges", according to Friedman. There is no visual designer, and no claim of compatibility with existing Microsoft XAML code, though developers who understand hand-written XAML will be at home.
The significance of Xamarin Forms is not only in the productivity it promises, but in the way it draws Xamarin closer to Microsoft in its development strategy. Xamarin Forms supports Visual Studio Shared Projects, shown for the first time at Build, which let you choose which code is shared and which is target-specific.
Running a Storyboard app designed in Visual Studio on the iOS simulator
It is the same approach used by Microsoft's Universal Apps (that run on Windows 8 and Windows Phone 8), though Xamarin Forms does not yet support Windows 8. However, Xamarin does now support Microsoft's Portable Class Libraries, which let you write .NET code that will run on multiple targets. Friedman says that full Universal App support is likely in future.
"I think it is the right strategy, and if it does take off, which I think it will, we will support it," Friedman said.
Xamarin's chief says that its partnership with Microsoft is recent. "Until November of 2013 we did not have a partnership with Microsoft, really, and no official support. That changed last November at the launch of Visual Studio 2013, where we announced that we were working together. It's real."
The outcome of the partnership is not only early support for new features like Shared Projects, but also access to customers. "Microsoft has actually introduced us to a very large number of customers over the last month, including invitations to brief customers at their EBC (Executive Briefing Center) in Redmond. Part of the advantage to Microsoft is that it gives them the ability to get into a mobile conversation, where they couldn't previously," Friedman said.
Xamarin 3 also adds support for F#, and for the NuGet package manager in Visual Studio or Xamarin Studio.
If you take Xamarin's latest offerings together with Microsoft's recently announced Cordova support, then Visual Studio becomes a real contender for cross-platform mobile development, particularly for those with existing skills in C# and XAML. This fits exactly with Microsoft's new strategy, as evidenced by its release of Office for iPad, where cloud services like Azure and Office 365 are consumed by a broad range of clients.
The snag is that Xamarin is an expensive additional subscription for smaller developers, which limits its take-up, but this will not trouble enterprise customers. ®
Sponsored: Customer Identity and Access Management