Automatic incremental build number in xCode 4.3


I have always wondered how to get a better build number in my projects, instead of having to change is manually. So, I finally googled it and found a solution. Or better yet, found several… but none working for xCode 4.3.

In xCode 4.3 you can actually change the build number manually in the project settings. I have not found a solution yet to activate an automatic build number update, however I have not search so much for that either.

So how did I tackle it? Well, when building your target in xCode you can add custom stuff xCode should do. For instance, it could run a script.
So, what I did was I opened my project and added the following line of code in an new build phase.

Now I see you thinking “Whuuut”?? No worries, I made some images to explain it. Just so you know, you should replace MYPROJECTDIR with your project dir name and file name.

The how to

First of, open your project and click on your project in the “Project Navigator” (Pic.1).



Now, in my project you see I have build 19, right? Well, lets switch to the “Build Phases” tab (Pic.2)



At the bottom right you see a little cute button popped up, called “Add Build Phase”. Click it and choose “Add run script” (Pic.4).



Add the code I wrote above in the “Shell” text area. Now move the area upwards so you got it right below “Target Dependencies”. (Pic.4)



Now you are basically done. You could build and run to the simulator and the build number will be updated. One thing you should know though is that xCode caches the plist files for your project, so even though you build and run it might be that xCode hasn’t understood the update yet. Just open the ***-Info.plist file in finder and you’ll see the update.

Hope this helped, if so… FB LIKE IT! 😉


Posted in Apple, Development, iOS, iPhone, Objective-c, OSX, XCode Tagged with: , , , , , , , ,
9 comments on “Automatic incremental build number in xCode 4.3
  1. Tom says:

    Yours is not working for me, but this one is working :

    CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $buildPlist)
    CFBundleVersion=$(($CFBundleVersion + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" $buildPlist

  2. Paul Peelen says:

    Mine works perfect for me, but I do have to change my paths for every project.
    You code seems that is should work nicely. Thanks!

  3. DC says:

    I am receiving an error with Tom’s code. Are you wanting to increment the CFBunderVersion or the buildNumber?

    line 5: Unrecognized Command + 1: syntax error in expression (error token is “Command + 1”)
    Command /bin/sh failed with exit code 1

  4. DC says:

    # Auto Increment Version Script
    echo $buildPlist
    CFSVString=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$buildPlist")
    CFBundleVersion=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist")
    BUILD_NR=$(($BUILD_NR + 1))
    #echo $BUILD_NR
    #echo $CFBundleVersion
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $CFBundleVersion" "$buildPlist"

  5. Paul Peelen says:

    Its really weird, since I use this exact same code in about 10 projects, and they all work for me.

  6. Paul Peelen says:

    I updated the post now to use the “new” color-coding syntax, so maybe it was just an encoding problem when coping. Hope it works better now for those of you whom had problems.

  7. Jonathan says:

    DC’s comment on January 25th was the only piece of code that worked for my xcode installation

  8. Jobe says:

    the script seems to not like a decimal value in the bundle version.

    After changing the “Bundle Version” on the info tab to an integer value it works fine for me

  9. I was having issues myself. I suspect xCode changed the CFBundleVersion to a float value in some release. The following code will handle that…

    buildNumber=$(/usr/libexec/PlistBuddy -c “Print CFBundleVersion” AutoIncrementBuildNumbers/AutoIncrementBuildNumbers-Info.plist)
    buildNumber=echo $buildNumber + 0.1| bc
    /usr/libexec/PlistBuddy -c “Set :CFBundleVersion $buildNumber” AutoIncrementBuildNumbers/AutoIncrementBuildNumbers-Info.plist

Leave a Reply

Your email address will not be published. Required fields are marked *