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.

<script src="https://gist.github.com/hstaudacher/d78b154509e2783cfcc2.js"></script>

3 Comments
  • Paulo Carvalho
    Posted at 6:32 pm, April 8, 2015

    Implemented this and works very well 🙂

  • Paulo Carvalho
    Posted at 6:33 pm, April 8, 2015

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

  • Hemant Patel
    Posted at 8:52 am, July 4, 2015

    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)