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

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

logosBumping 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.

  • Paulo Carvalho
    Posted at 18:32, 2015-04-08

    Implemented this and works very well 🙂

  • Paulo Carvalho
    Posted at 18:33, 2015-04-08

    Would be nice to wrap the signing command and zipalign as well.

  • Hemant Patel
    Posted at 08:52, 2015-07-04

    Hi Holger Staudacher,

    First of all thanks of great post and support to cordova developers.
    I need your kind support to have same hooks like you have develop for versionCode(Android) and CFBundleVersion(iOS) but for version as I have different version name for android-versionName (android) and ios-CFBundleShortVersionString(iOS) and for that I need to update version name on build for each platform everytime.

    looking for your prompt support for the same.

    Thanks in advanced,
    Hemant Patel (Radixweb,India)