What's New in Apache Cordova 4?
In this article, I'll provide an update on the latest major release of Apache Cordova, a popular open source framework for hybrid applications. A lot of interesting things are happening as Cordova becomes an even more important part of many organizations' mobile application strategy.
Apache Cordova is a free, open source framework for building cross-platform native applications using HTML5. The creators of Apache Cordova wanted a simpler way of building cross-platform mobile applications and decided that the best approach was to use a combination of native and web technologies. This type of mobile application is called a hybrid application.
Cordova is used for consumer applications as well as many enterprise applications. On the consumer side, many games and personal applications have been built using the platform. On the enterprise side, Cordova has been widely adopted by many companies, as well as being included in the development platforms that software companies sell to enterprises. Examples:
- Adobe PhoneGap is a downstream distribution of Apache Cordova with some extra stuff added. On the PhoneGap website, you can browse a catalog of consumer apps built with the technology. Adobe recently released the PhoneGap Enterprise app to help organizations distribute content to remote users.
- Apache Cordova can also be found in IBM Worklight, an enterprise mobile application development platform (MADP) from IBM, as well as products from Oracle, Salesforce.com, and many others.
- Until recently, I was responsible for the SAP Mobile Platform hybrid SDK, a set of enterprise plugins for Apache Cordova from SAP.
Because of all of this attention, a lot of people are working on Apache Cordova. The most interesting piece for me is how the different device manufacturers have gotten onboard with the project. Development teams from Amazon, BlackBerry, Google, Intel, Microsoft, Mozilla, Ubuntu, and more are involved. Pretty much everybody in the smartphone space (except for Apple) has made an investment in the project.
So what's changed in the latest release of Apache Cordova? A few big things, but not very much overall. The Cordova team works diligently to add new platforms whenever possible. A couple of new APIs have cropped up lately, but for the most part the dev team seems more interested in removing APIs than adding new ones. Features generally make it into the product as soon as they're ready.
In the rest of this article, I'll highlight what I see as the big parts of this latest version of Apache Cordova.
Release Strategy
The Cordova team is constantly working to improve the framework. In the Cordova 3 timeframe, framework releases were a big deal and appeared on a regular near-monthly cadence. With the later releases, the Cordova team has broken out the different components into individual release plans. Instead of the Cordova core, command-line interfaces (CLIs), and plugins all being bundled together for a formal release, everything has been broken out into separate release schedules. As an example, when the team working on a particular plugin for a particular platform is ready, the plugin is released. One team doesn't have to wait for all of the other platform teams to coordinate their efforts; instead, each team simply completes its work, tests everything, votes on a release, and then releases it. The same thing is true for the Cordova CLI. As capabilities (or bug fixes, of course) are added to the CLI, it is released when ready, instead of waiting for the other components to be ready as well.
With so many teams working on components in parallel, it's been challenging to sync to a solid release cadence. As an example, version 4 of the Cordova CLI was released right before PhoneGap Day in October 2014, but the Android platform version with the pluggable WebView (described later) wasn't released until March 2015.
Because of potential compatibility issues between the CLI and target platforms, each CLI release is pinned to a specific set of platform releases. If you want to add a specific newer platform to your project, you will need to append the platform release to the platform name in the cordova CLI command. For example, to add an Android platform to an existing project, you use the following command:
cordova platform add android
The Cordova CLI will add the Android platform version that has been associated with that CLI release. To add a newer platform than was pinned to the CLI, add the platform version to the command:
cordova platform add android@platform_version
For example, to use the Android 3.7.1 platform in your project, you would issue the following command:
cordova platform add android@3.7.1
Look at the release notes for any specific version of the Cordova CLI; the Cordova team should publish the list of pinned platform versions for that release.
Command-Line Interfaces
Cordova provides two CLIs: the Cordova CLI that simplifies the process of working with a Cordova project; and Plugman, a set of command-line tools for managing Cordova plugins. Plugman came first, as a way to help plugin developers create new plugins and add them to their Cordova projects. The Cordova CLI (which uses Plugman under the covers) was developed later as a way to help the everyday hybrid application developer work with Cordova projects. Although sometimes developed by different teams, over time the Cordova developers noticed some common functions used by both Plugman and the CLI. In an effort to simplify the development workload for these two tools, the Cordova team created a set of common libraries that are used by both CLIs.
These common libraries don't really affect the end user of these tools, but they help align how both CLIs operate, simplifying the development effort required to work on the tools.
Save/Restore Plugins
In older versions of Apache Cordova, the Cordova application project was closely bound to the development environment on the system where the application was created. The Cordova CLI interacted with the local mobile platform SDKs, and it was really hard for one developer to give another developer access to the project if the target system wasn't running the same version of almost everything.
With the Cordova CLI 4.0 release, the team added commands that allow a developer to store plugin information for the project in the application project's config.xml file. The commands were experimental in that release, so you had to add a special flag on the command line to utilize them, but the capabilities were in place. At the time of writing, this capability was to be moved from experimental status to production. (At this point, it might already have been moved.)
To take advantage of these capabilities, the developer will use the Cordova CLI to save the plugin configuration and then pass the project's config.xml file and the contents of the project's www folder to another system or developer. With the files in place on the new system, a simple Cordova CLI command will restore the listed plugins to the project in its new location.
Pluggable WebView
The WebView is a native application component that renders the web application content in a Cordova application. It's essentially a browser window you can embed in a native mobile application. Until recently, Apple and Google implemented the native WebView using a different rendering engine than the one found in the native browser. This design had the potential side-effect of making a hybrid application run slower than the same content would run in the native browser. Additionally, with different rendering engines in play, a web application could render correctly in the native browser but not so well in the WebView. Both companies have now resolved this issue with newer devices; for the most part, the WebView now uses the same rendering engine as the browser.
In January 2015, Google announced that it would no longer back-port bug fixes to older versions of the WebView used by Apache Cordova. This change wasn't because of Cordova, but certainly affects Cordova developers in a big way. If your application encounters a rendering problem when running on an older Android device, you're pretty much out of luck in this situation.
The Cordova team is planning a solution to this problem. Soon, developers will be able to add a compatible WebView to a Cordova project by using a new command added to the Cordova CLI. The first implementation is through the Intel Crosswalk Project. Crosswalk is a browser runtime engine that uses the latest version of the Blink rendering engine. On modern Android smartphones, Blink is already the engine distributed by Google. Where Crosswalk becomes important is on older devices where Google is no longer providing bug fixes. Crosswalk will be implemented first, and other options will be made available as well.
Third-Party Tools Support
Not part of the Cordova release, but interesting anyway, is how many third parties have added support for Cordova to their products. One of the goals of the Cordova CLI is to provide tooling that can be consumed by other tools; Cordova provides the "plumbing," and you use whatever tools you want to code, test, debug, and build your Cordova apps.
As I worked on my latest Cordova book, I noticed plenty of third-party tools and frameworks available now that specifically target hybrid development or are Cordova-aware. The Ionic framework, for example, is an open source HTML5 framework specifically targeting hybrid applications like Cordova applications. Another is Onsen UI, which is billed as being Cordova/PhoneGap-friendly. Developers working on hybrid applications will find a lot of frameworks out there built with Cordova in mind.
On the tooling side, Adobe finally released the Brackets open source text editor after announcing it several years ago. This awesome editor is easily enhanced through a robust catalog of third-party plugins for Adobe PhoneGap as well as Apache Cordova. It's a great tool for managing your Cordova projects.
I was recently introduced to the JetBrains WebStorm IDE. What's cool about this tool is its built-in Cordova and PhoneGap integration. Simply enable the appropriate options, and suddenly you can issue Cordova CLI commands directly from within the IDE.
The Eclipse Foundation recently released the Hybrid Mobile project (with the acronym THyM), which is a specific set of tools for building hybrid applications based on the Eclipse IDE. This project was started by the folks in Red Hat's JBOSS team, and it allows you to manage the entire Cordova project lifecycle from within Eclipse.
The most important tool release (in my eyes) is Microsoft's Visual Studio Tools for Apache Cordova. This plugin to Visual Studio adds a complete solution for managing your Cordova projects in Visual Studio. Not only do you get Cordova-specific tools for Windows applications, but the team working on the toolkit added support for JavaScript debugging of Android and iOS applications—all from within Visual Studio. With this tool, you can create a Cordova project for those platforms and do live, real-time JavaScript debugging, all from within visual Studio. Open an application project, set one or more breakpoints in the application's JavaScript code, and the debugger will halt application execution at the breakpointed lines and let you step through the code, view variable contents, and more on all supported platforms. Really cool stuff.
For details on all of these topics (and more ), see my book Apache Cordova 4 Programming.