How do you handle version and build numbers?

As I understand it, I can set a version in <widget> of config.xml. Then when I build my project, Cordova somehow generated “build numbers” out of that.

But each build for a version seems to get the same build number (iOS identical to the version, for Android the versionCode is some math calculated out of the major.minor.patch => major0minor0patch), so not very useful.

There also seem to be iOS and Android specific “build numbers” I can set in config.xml: android-versionCode and ios-CFBundleVersion. But then I have to manage these myself, similar to the version.

How do you handle version and build numbers?
Do you have the same build numbers on iOS and Android?
How do you handle builds of Ionic? Does it also have a version number somehow?

2 Likes

Hi did you found a solution for this? There are hooks and something like that, in the hook we can override the build number manually but we are searching for a parameterized variables like that
version="$VERSION_NUMBER", and on the hook we can change the parameter reading from another configuration file.

Can you help?

No, as I do not understand what you are asking me.

I right now manually increment the android-versionCode and ios-CFBundleVersion in config.xml for each build where the build number is relevant.

My intention was, on every production build I would like to increment an iterator an variable, and this variable I would like to use in my config.xml. I’m not sure if there is a possibility to use VARIABLES in config.xml and cordova builds?

This sounds like a problem for a build script or process modification.

#1 In Cordova world hooks exist, #2 in Ionic world you can modify what script is executed by modifying the scripts portion of your package.json. #3 If you use a CI service, that can probably also doe things before actually calling ionic cordova build.

Yes I saw the hooks and there I can run a javascript which is reading changing config.xml file and set version number.
But probably this all is a little bit to complicate and probably it is better handle the version number by hand.

We have to synchronize the sentry.io RELEASE number with the cordova VERSION, doing this manually often is something anybody probably forget. But setting an automatic version number not a build number is perhaps also not a good idea.

On my CI process (I use fastlane) I base everything on the ios-CFBundleVersion in the config.xml.

I have it formatted like this: MAJOR.MINOR.PATCH.BUILD (ex: 1.1.0.2)

After changing the ios-CFBundleVersion you can remove the last number to set the version attribute like this: MAJOR.MINOR.PATCH (ex: 1.1.0)

And calculate the android-versionCode attribute from the ios-CFBundleVersion:
MAJOR * 100000000 + MINOR * 100000 + PATCH * 1000 + BUILD

I use a custom fastlane lane to open the config.xml file and change the values (you can do this using gulp or a npm script)

1 Like

No, that is actually absolutely what they should be used for.

Same here - I imagine Sentry has an API one can call with a new deploy/release or even by setting the value directly in the code.

Great, can you share more information on how you integrate fastlane? It sounds good!

I know @Sujan12 is working on a tutorial to integrate fastlane with ionic on ionic.zone.

I followed the tutorial of fastlane and used the cordova plugin for it.
The only custom piece of code I wrote was for changing the version number as described in my previous post (I used the gem nokogiri to modify config.xml).

5 Likes

Just copy this file into hooks folder and that’s it. You can customize it to your needs.
(need to npm install xml2js)

EDIT: I’m updating this link as I changed my githubname: https://gist.github.com/raschidjfr/636aac1841fdc2dbc2407cfc9d57df4c

I’m using bump (https://www.npmjs.com/package/@fabiospampinato/bump) and cordova-set-version (https://www.npmjs.com/package/cordova-set-version). I created a node script to have versionnumbers of package.json and config.xml in sync:

scripts/version_config_xml.js

#!/usr/bin/env node
const cordovaSetVersion = require('cordova-set-version');
cordovaSetVersion();

then I ran:

bump patch --postbump "node scripts/version_config_xml.js"