An Apache Cordova hook to auto bump iOS CFBundleVersion and Android versionCode

April 7, 2015 | 1 min Read

Bumping versions is a topic that should be fully automated from my point of view. Doing it manually guarantees errors for sure. I experienced it so many times as well :) . Recently we have published a build service for Tabris.js which utilizes Apache Cordova to build Tabris.js apps. We wanted to leave the versioning up to you in order not to create pitfalls like silently incrementing version numbers. Such a silent version bump can cause problems e.g. when re-creating an app in a build service (e.g. Phonegap Build) using the same app id. If a previous version of the app was already published using a higher version, you have no chance to publish your new app to the stores. The only chance to prevent this is to manually bump versions in your config.xml.

Luckily Apache Cordova has the concept of hooks. A hook can be seen as a “custom build step”. You can change nearly everything in your project using such hooks. So, bringing the versioning problem and the hooks together, we came up with a Cordova hook that increments the iOS CFBundleVersion and the Android versionCode automatically by timestamp. The first working version is available as GitHub Gist. Feel free to copy, use and change it as you like.