Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-Increment Build Number for Multiple Targets in Xcode

I have a "Free" and "Paid" version of my app, and I want to auto-increment both of the build numbers simultaneously, because sometimes I test with the "Free" version and sometimes I test with the "Paid" version depending on what I am doing. These are essentially the same codebase, I just have two targets with a preprocessor directive defined with the "Paid" version to unlock certain things.

I am using the code in this question: Version vs build in XCode

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

I think I just need to add two more lines specifying the path to the other $INFOPLIST_FILE along the lines of:

 "Print CFBundleVersion" "NEW_PATH/$INFOPLIST_FILE"

and increment it, but how do I get the path to one target's Plist when I am building the other?

like image 943
Jon Mattingly Avatar asked Jul 28 '13 18:07

Jon Mattingly


1 Answers

An update for the latest Xcode, first change "Versioning System" to "Apple Generic" in "Build Settings" tab for all of your targets. versioning system: Apple Generic

And add this line in "Run Script" of "Build Phases" tab for all of your targets:

agvtool next-version -all

agvtool increments build number for all targets agvtool will do the increment job for you!

like image 200
benck Avatar answered Oct 03 '22 18:10

benck