Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto increment build number xcode?

Tags:

xcode

iphone

I am trying to implement the answer here:

Better way of incrementing build number?

but cannot get it to work properly. It fails with error 2 saying "No build number in plist"

But if I put a build number in my plist, the script clears it on the next build, then the same thing happens all over again.

Any ideas?

like image 729
ourmanflint Avatar asked Sep 11 '12 12:09

ourmanflint


2 Answers

Here's how I increment build numbers:

In the Target > Summary tab, set the initial build # enter image description here

Then use this script to increment the build number:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
buildNumber=$(printf "%04d" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

or if you want build numbers in hex:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$((0x$buildNumber))
buildNumber=$(($buildNumber + 1))
buildNumber=$(printf "%04X" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
like image 137
FluffulousChimp Avatar answered Sep 26 '22 23:09

FluffulousChimp


My solution is the following:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(echo $buildNumber | sed 's/0*//')
buildNumber=$(($buildNumber + 1))
buildNumber=$(printf "%04d" $buildNumber)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

Using sed to remove leading zeroes, incrementing the value and printing it back in the plist file using a four-digit-zero-padded number.

like image 28
Fabiano Francesconi Avatar answered Sep 24 '22 23:09

Fabiano Francesconi