Automatic build numbering


#1

Anyone know of any hook that automatically updates the build numbering when building?
I’m keep forgetting to doing it manually (and it’s unnecessarily time-consuming)
I’m not looking for a automatic version updater, as that would just cause problems, but a automatic build updater, would help when releasing new beta builds, and fix statistic tracking in for instance hockeyapp.


#2

You could make a before_build hook to change your app version in config.xml or make it stick a build number in your html/js. There are several more hooks that you might want to use instead but you can write them all in nodejs. Checkout the docs on github for cordova cli hooks if you want more info. There is also a nice article about some basic but useful hooks that should help you get started.

Also if you get a build hook working to increment the build number somewhere please share it as I would also find this useful.


#3

Yea, I have already implemented that article… it’s great.
I wish there was a hook database where you could easily search for useful hooks. Googling for them is a pain!

I will take another cack on using the replace_text hook.


#4

Ok, I have a semi dirty version working based on the ‘replace text’ hook.
I have made a gist of the hook.
Right now it only suffixes the build number to the version number. I would like to in the future separate it out to a separate ‘build’ metadata, that will be read correctly by Hockeyapp.


#5

Updated gist with bugfix.


#6

Thanks for that. I think it might be nicer if you made it replace the build number in a config.js so you could access it while the app is running easily. Looks like all you have to do is change the file path and it should work. This seems easier then trying to make it a separate ‘build’ metadata. I already have a config.js which I store my apiUrl in as mentioned earlier so the javascript approach works nicely for me.

If you don’t like this idea are there any benefits to it being in config.xml instead of your javascript? Is there a way you could access it from the config.xml while running to display it nicely for instance on a settings page? Also I don’t know if the build number being appended to the version number will work nicely with google play or the app store haven’t tried it though.


#7

You could definitely update a js file as well.
All you need to do is add the path to the build files array, and include the ‘BUILDNR’ placeholder where you want the build number to be included.

When working with version and build numbers, they are usually handled separately. One is used to track releases (version numbers), and the other to track development versions (build).

We use hockeyApp to distribute our beta version, and they let us breakdown statistics and reports by version and build.

If you want to make it simple, you can always append the buildnr with a dot instead of a dash:
1.0.0.1056
Where the build number is the last quintet. But yes, the plan is to move the buildnumber away from the version number all together.

The reason for using the config.xml file, is because that’s where ionic/cordova retrives the info when including it in all the system files for the different platforms.


#8

#onlyfornoobslikeme - Remember to create the build.json in the resources directory…


#9

[update]
If you want to separate the build number from the version number, you can add the following to the tag in your config.xml:

version="VERSIONNR" android-versionCode="BUILDNR" ios-CFBundleVersion="BUILDNR"

so it looks something like this:

<widget id="APPID" version="VERSIONNR" android-versionCode="BUILDNR" ios-CFBundleVersion="BUILDNR" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">

(text in uppercase are placeholders)


#10

Thank you. I also found this to be very helpful.


#11

I’ve just created my very first hook, which increments the build numbers directly in the project’s config.xml. Here’s a gist if anyone is interested.


#12

Looks a lot smoother than my approach. I will definitely try it out on my next app.


#13

Great hook.
If anyone want’s to update the “version” part (the one that looks like 0.1.2), you can add this to the js code:

// Get the version string (format is x.y.z) and split it to its components
var currentVersion = obj['widget']['$']['version'];
var currentVersionComponents = currentVersion.split(".");

// Increment the z value
currentVersionComponents[2]++;

// rebuild the version string, and set it on the object
var newVersion = currentVersionComponents[0] + "." + currentVersionComponents[1] + "." + currentVersionComponents[2];
obj['widget']['$']['version'] = newVersion;

#14

Excellent work ! Thanks for saving me time


#15

Old thread, but there is a cordova plugin that can work just as well here: https://www.npmjs.com/package/cordova-build-increment

It will read your config.xml for android-versionCode and ios-CFBundleVersion, and auto increment them after each build, and can be set to only increment on --release versions, not debug builds.


#16

dont work from me

config.xml build numbers not changed

after 5 builds