by Tim Anderson
If your app needs to run on Windows, Mac, Android and iOS, which tool should you choose? Tim Anderson looks at the options.
HardCopy Issue: 64 | Published: October 30, 2014
The development landscape has never been more diverse. Important client platforms today include Windows, Mac, iOS, Android and web browsers, while other mobile platforms such as Windows Phone and Blackberry are also significant. Such diversity has stimulated interest in cross-platform development tools as businesses try to reach the broadest possible market. But is it possible to go cross-platform without compromising the user experience on each device? And for those who do go the cross-platform route, what are the pros and cons of the available tools?
There will always be compromise in a cross-platform project. If you have the luxury of developing for a single operating system then you can use the native SDK, get the best possible performance, and fully integrate with the features of the chosen OS and device. That said, the quality of cross-platform tools has improved to the point where excellent performance and interface integration becomes possible, given some effort. If you dismissed cross-platform mobile development a few years back, then it is time to take another look.
It is not usually possible to share 100 per cent of the code. All the tools described here allow conditional code that targets specific platforms, as well as native extensions that give access to unique features or optimise performance bottlenecks. The amount of code you can share depends partly on the approach you take, and partly on the requirements of the specific application.
What about Google’s Chromebook? This is a tightly locked-down platform which is essentially a Chrome browser with some offline capability. It is popular in education thanks to its low price and easy management. However applications for Chromebook are web applications; if you have developed a web application it will work on Chromebook, though you may want to add offline features such as local storage.
The native SDK for Windows is largely C/C++, with .NET a widely used framework that wraps the API for languages including C#, Visual Basic and F#. Apple’s OS X and iOS use Objective C, an object-oriented version of C which is quite unlike C++. Android’s native SDK uses Java, with an option for C/C++ using the Android NDK, although Google does state that “the NDK will not benefit most apps”. Windows Phone 7 uses Silverlight, while Windows Phone 8 adds an option for Windows Phone Store apps that use either .NET or C/C++.
How can you wrest these diverse SDKs into one language and tool that targets them all? There are two common approaches.
The main issue with the web engine approach is that web pages have a different look and feel from native applications. Everyone is familiar with the web, but in the context of an application a web-based user interface is unexpected. That said, the styling possibilities in a modern browser are so extensive that developers can mimic a native look and feel.
Frameworks that take this approach include PhoneGap/Cordova and Sencha Touch.
The other approach is cross-platform compilation. One thing that all the major platforms have in common (including Windows Phone since version 8.0) is support for native executables. This makes it possible to cross-compile from a single source, creating native binaries for each platform. A further twist is that you can compile a runtime into an application and have that runtime execute your code, which may be in a language not normally supported by that platform.
Native binaries give the best performance and also make it possible to use every feature on each device, though you still need conditional code if you want to go beyond the subset of features that every platform has in common. Tools that bundle a runtime into the binary, such as Xamarin and Adobe AIR, give larger app sizes, though this is not usually a big problem thanks to smart optimisation.
The main issue with cross-platform compilation is what to do about the user interface. There are several problems. One is that controls such as buttons, menus and lists look and sometimes behave differently on each platform. Some tools overcome this by using custom-drawn controls, with conditional code in their libraries so that the correct control is drawn on each platform. Getting this completely correct is hard, especially when the platform vendor updates the operating system, so there may be things that are not quite right.
Another approach is to abstract the controls, so that a button component in the cross-platform tool calls the native API to render a button. This results in a more authentic native application, but with the challenge of abstracting the controls successfully so that developers can use all the features without unexpected behaviour.
If you’re developing action games then graphics capability and performance come to the fore, while use of native controls tends to be a non-issue; gamers just want an immersive experience and do not mind if each game has a unique appearance. Casual or puzzle games are less demanding, and can be built with any of the tools described here.
WebGL is an API for rendering 3D graphics on an HTML5 canvas element. It is based on a subset of OpenGL, an API for accelerated 2D and 3D graphics. WebGL offers the prospect of cross-platform mobile game development using the browser engine, but support is limited. On Apple’s platform you need iOS 8. Google Chrome supports WebGL on Android, but the stock Android browser does not. Mobile Internet Explorer supports WebGL in Windows Phone 8.1.
A third solution is not to attempt a cross-platform user interface at all. You can write non-visual code in a cross-platform tool, but create a different user interface for each platform. Until recently, this was the official approach taken by Xamarin, for example. The snag is that less code can be shared, which means more development effort.
Key examples of the cross-compilation approach are Xamarin and Embarcadero RAD Studio, which includes Delphi.
Coding the back end
Most apps rely on back-end services to supply their data. Many apps are designed so that all the user’s data is synchronised to the cloud, letting users move between devices and get the same data and configuration on each one.
Despite the above, the extent and quality of support for specific platforms varies. If you are using Microsoft’s platform, for example, and want to integrate with Azure Mobile Services, Active Directory or a Web API ASP.NET project, then you will find more libraries and sample code for C# than for other platforms, even though Microsoft publishes SDKs for iOS, Android, .NET, Java, PHP and more. Such a situation might point you towards Xamarin.
The best supported platforms tend to be the ones that are most popular. Use Apache Cordova, for example, and you will find great support, especially since it is essentially a web platform.
Cordova and PhoneGap
PhoneGap was developed by a company called Nitobi, to enable mobile apps that wrap the browser runtime. Nitobi was acquired by Adobe, and now the core PhoneGap technology is an open source Apache project called Cordova, while PhoneGap itself remains an Adobe product. Aside from support, the added value from Adobe is a cloud build service, which avoids the considerable pain of managing multiple mobile SDKs on your developer machine.
Adobe has also announced PhoneGap Enterprise which will add features including business collaboration, simple app editing, and integration with Adobe Analytics and Adobe Target for use in optimisation and marketing. PhoneGap Enterprise is currently in closed preview.
Cordova is the most mature and popular approach to cross-platform mobile development. It offers a high level of code reuse, and code can be shared with browser-based web applications as well as mobile apps. Access to device-specific features becomes possible through plugins covering various capabilities such as accelerometer, calendar, camera, contacts, storage, media players and barcode scanning.
Currently in beta, the goal of Intel INDE is to bring together Intel’s native compilers and tools with cross-platform development for Android and Windows.
INDE is a suite of tools, many of which are fully production-ready. The tools include Intel’s C++ compiler for Android, Threading Building Blocks for simplified concurrent coding, Graphics Performance Analyzer (GPA) tools, Frame Debugger for troubleshooting rendering issues on Android, and Intel HAXM (Hardware Accelerated Execution Manager) for high performance Android emulation. INDE also manages the configuration of your development environment, whether Eclipse, Android Studio or Visual Studio, and the downloading of the Android SDK and NDK. You can code in either Java or C++.
When you install INDE you do not get the complete installation, but rather a configuration tool that lets you select which INDE components you require, and which IDE you want to use.
INDE is part of Intel’s push for Android, and although ARM is a supported target, it makes better sense for high performance apps that target Intel devices.
Embarcadero RAD Studio XE7
RAD Studio is Embarcadero’s development tool suite based around Delphi and C++Builder: two rapid application tools that let you write code in Object Pascal or C/C++ respectively. Key features of the suite include two-way visual development, so you can use visual and non-visual components either with drag and drop or in code, and native code compilation for fast binaries with few dependencies. The suite also includes an HTML5 development environment called HTML5 Builder.
Embarcadero’s recent efforts have been focused on cross-platform support for Mac, iOS and Android. The IDE runs only on Windows, but a typical set-up is that you install on a virtual machine on a Mac, using agents on the OS X side to compile and build for Mac and iOS.
Cross-platform projects use the FireMonkey GUI framework, which is incompatible with the VCL (Visual Component Library) for Windows but shares the same language and runtime library.
The latest release adds a multi-device designer for maximising shared GUI code, while still allowing platform-specific changes. There is also a feature for connecting apps locally over Ethernet or Bluetooth, called App Tethering, and new server middleware called Enterprise Mobility Services.
RAD Studio is an obvious choice for existing Delphi and C++Builder developers, and also strong if you have desktop as well as mobile targets in mind. It does not support Windows Phone. Despite its capability, it is a niche tool which means that finding libraries to support your favoured web services may be more difficult, though you can be sure it will be possible given sufficient effort.
Xamarin is a cross-platform mobile development company and tool which has its origins in the Mono project, an open source implementation of Microsoft .NET and C#. Company co-founder Miguel de Icaza was the creator of Mono. Xamarin came up with compilers for iOS and Android, and found immediate success among Microsoft platform developers who wanted to port C# code for mobile apps, or to create new mobile apps using a familiar language.
Xamarin’s approach is to focus on non-visual code for cross-platform support. This ensures a native experience and optimised GUI on iOS and Android. That said, the latest version, Xamarin 3.0, introduces Xamarin Forms, which lets you define a GUI layout in XML using a version of Microsoft’s XAML. The controls are rendered by the native operating system, rather than being custom drawn.
Although Xamarin does not support Windows or Windows Phone directly, it does support Microsoft’s Portable Class Libraries, so you can write code that runs on Windows platforms as well as on Xamarin. The IDE for Xamarin is either Visual Studio, or Xamarin Studio which runs on Windows and Mac.
Microsoft’s recent push towards “any device” support implies a need for something that allows developers to use a Microsoft platform, either in the cloud or on-premise, to create apps for iOS and Android. The evidence is that Xamarin is a key partner for this support. Xamarin was prominent at Microsoft’s 2014 Build conference. In addition, Microsoft has open-sourced most of .NET, including the next generation of the C# compiler, which means that Mono and Xamarin can increasingly use the same code as Microsoft .NET. These factors make Xamarin a strong choice for existing Microsoft platform developers.