Xcode 11 moved version handling to the .pbxproj file, in addition to Info.plist, which broke my script to automatically increase build number on each build. Solution for Xcode 11/12 is shown below.
Background – pre Xcode 11 / Xcode 12
Before Xcode 11 the “normal” way to auto increment build number was to read current build number from Info.plist using the MacOS PlistBuddy tool and then increment that number and write the updated build number back to Info.plist, again using PlistBuddy. Or you could use avgtool or some 3rd party solution.
However, with Xcode11 (and currently Xcode12) version number and buildnumber are set in the pbxproj file, and Info.plist only reference what is set in pbxproj.
This change got my old script to generate an error on build: Command PhaseScriptExecution failed with a nonzero exit code
$(CURRENT_PROJECT_VERSION) + 1: syntax error: operand expected (error token is "$(CURRENT_PROJECT_VERSION) + 1")
Command PhaseScriptExecution failed with a nonzero exit code
This is what Info.plist now looks like in Xcode11 / Xcode12, i.e. there is no longer an actual build number to read from Info.plist, only a reference to what is set in the pbxproj file.
<key>CFBundleShortVersionString</key> <string>$(MARKETING_VERSION)</string> <key>CFBundleVersion</key> <string>$(CURRENT_PROJECT_VERSION)</string>
Solution for Xcode 11 / Xcode 12
So, in Xcode 11/12 we now need to update the pbxproj file instead of Info.plist.
Use this script to auto increment build number:
buildNumber=$(xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION =') buildNumber=`echo $buildNumber +1|bc` xcrun agvtool new-version $buildNumber
To add the script in Xcode 12, follow these steps:
- Select your Project Target (Target, not Project)
- Select Build Phases
- Add a new Build Phase by clicking the plus (+) icon on top left
- If you wish you can rename the new Build phase, e.g. Set Build Number
- Copy the script above and paste it
- You can leave all other Build Phase settings as default
- Done – Build your project and watch build number increment with 1 for each build
This was latest tested on Xcode 12.5 and macOS Big Sur 11.5.2 on a MacBook Air M1
Did this solution help you?
I hope this helped! Please comment if it did, or if you had any problem with it. Also let me know if you got it working (or not) using other versions or if you found a better solution – it will help me and others!