Big updates to Apache Cordova

Over the past few days, there have been some pretty big updates to Apache Cordova. If you haven’t been following their blog (they don’t have a “subscribe” feature so I use a IFTTT email rule), then you may have missed out on the announcements. Here is a quick review of what’s new:

Android 4.0

So, what you may not know (and I’m honestly curious about how many people are aware of this) is that each platform (the actual bits you get when you add a platform to your Cordova project) is it’s own separate project and has it’s own version. I’m willing to bet most Cordova developers don’t think about this very often, but sometimes pretty important updates happen to one platform that you should be aware of. On April 15th, Android 4.0 was released, with the biggest feature being the support of Crosswalk as a pluggable web view. Crosswalk gives you a way to provide a consistent, modern webview in your Android Cordova projects no matter what version of the Android browser they have may on their device.

Another big change is that you must use the Splashscreen plugin if you want to use a splashscreen with your Android application. Previously you could get by with just config.xml changes, but now the plugin is required.

Finally, a new plugin (cordova-plugin-whitelist) is required to have whitelist support in your project. If you do not use this plugin, your app will act as if has no whitelist and will block all remote requests! Luckily the CLI now adds this by default, but be aware.

Plugins move to NPM (and updated)

Another big change is that plugins are now being loaded from NPM. As a practical matter you may not care, but the IDs used to load plugins have changed from org.apache.cordova.something to cordova-plugin-something. So for example, you would switch from:

cordova plugin add org.apache.cordova.device


cordova plugin add cordova-plugin-device

The old IDs still work, and will work for some time, but you will want to get used to the new naming scheme. Want to search for plugins via the CLI? Use:

npm search ecosystem:cordova


All of the plugins have had minor updates and you can see a list of changes on the blog post.

I’m scanning the list now, and there seems to be a huge amount of bug fixes. Things that stand out are:

  • "Added nativeURL property to FileEntry, implemented readAsArrayBuffer and readAsBinaryString." - This is nice!
  • "Unable to read android_asset directory through File API" - this bug fix lets you use the file system API to read from android_asset. I ran into this as well, so I'm happy to see it fixed.
  • Browser platform support for File and File-Transfer
  • </ul>

    Tools Update

    And finally, the CLI has updated. You'll want to do a npm update to get the latest (version 5). Notable updates include:
    • Support for plugins via npm as described above.
    • The State feature I blogged about for Ionic is now supported in Cordova as well. It is a bit different though. Unlike Ionic, the Cordova CLI will not save plugins and platforms by default. To save the fact that a project uses a platform or plugin, you must include --save in the command line call, like so:
      cordova plugin add cordova-plugin-device --save
      But if you forget, you can quickly save everything with two commands:
      cordova plugin save
      code>cordova platform save</code>
      When you save, data is stored within your config.xml file:
      <plugin name="cordova-plugin-whitelist" spec="1" />
      <plugin name="cordova-plugin-device" spec="^1.0.0" />
      <engine name="android" spec="4.0.0" />
      And to restore your plugins and platforms, you would do
      cordova prepare
    • </ul> You can read more details in the blog post. So... thoughts?
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for Extend by Auth0. He focuses on serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA