8

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?

2
  • Can you please elaborate on what do you actually mean by path? Jul 28, 2013 at 19:04
  • I meant the file path, i.e. "~/Projects/iOSApp/App." I figured out the question and answered below, if you're interested Jul 28, 2013 at 19:24

4 Answers 4

14

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!

3
  • 8
    Hey, thanks for the answer. Did you have a problem when using this command builds are being cancelled? I use Xcode 11.1
    – A. Buksha
    Oct 29, 2019 at 11:53
  • 1
    @A.Buksha I have the same problem and was wondering what was causing it...
    – Moumou
    Oct 29, 2019 at 13:18
  • Is necessary to set the "Current Version Project" key to start to work
    – Jorge Paiz
    Mar 3, 2020 at 13:54
5

I figured it out. You need to use the SRCROOT variable. This will give you the base directory for the project. From there, you need to manually specify the location of the info.plist files you wish to use, and run the PlistBuddy -c command with that path.

Here is an example that increments the "Free" version first and then increments the "Paid" version:

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

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$SRCROOT/Pro-Info.plist")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$SRCROOT/Pro-Info.plist"

You need to make sure you inverse the script for each target, so it uses the $INFOPLIST_FILE variable on the current target and you are specifying the location of the others. You could probably store these in custom variables or specify each one instead of using the $INFOPLIST_FILE variable at all, but they all do essentially the same thing.

0

If anyone is facing issue with avgtool, Please check this answer

https://stackoverflow.com/a/60073040/208308

I have solved my issue with the script shared in the above link without the use of avgtool.

0

To increment build number in the Xcode Server I am using

  1. Set: Current Project Version = 1 and Version System = Apple Generic. Can be found more in Apple documentation.
  2. Right click on the bot and choose Edit Bot...
  3. Open Triggers tab and add Pre-Integration Script
  4. Give a name (example: Set Build Version) and write script:
cd $XCS_PRIMARY_REPO_DIR # Change directory to project path 
xcrun agvtool new-version -all $XCS_INTEGRATION_NUMBER # Set build version same as integration number

Build number incremental using Xcode Bot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.