Xcode-Increment build number only during ARCHIVE?

I found several other posts that show how to add a script to increase the build number using the script:

Best way to increase build numbers?

Xcode Project Build Number

Can Xcode insert version number in library file name when creating?

But what I want to do only increases the build number when I use ARCHIVE (both before and after).

Example: If the current build number is 21, then when I select Product> Archive, the build number will be increased to 22, it will complete its process of building and creating an archive file with build number 22, and then when it finishes archiving, it will increase the number builds up to 23.

+51
xcode xcode4 osx-lion macos
Mar 24 2018-12-12T00:
source share
3 answers

Add the following script, as in the example shown in the first link you posted, but do it twice. Once at the beginning of the assembly and once at the end:

if [ $CONFIGURATION == Release ]; then echo "Bumping build number..." plist=${PROJECT_DIR}/${INFOPLIST_FILE} # increment the build number (ie 115 to 116) buildnum=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${plist}") if [[ "${buildnum}" == "" ]]; then echo "No build number in $plist" exit 2 fi buildnum=$(expr $buildnum + 1) /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "${plist}" echo "Bumped build number to $buildnum" else echo $CONFIGURATION " build - Not bumping build number." fi 

Many thanks to the authors of the questions you contacted in your question for the information that made me start this answer!

+74
Mar 24 2018-12-12T00:
source share

This is very similar to @Inafziger's answer, but a more concise set of code with the added benefit that the "Release" check is done using a checkbox in Xcode rather than a run-time variable:

enter image description here

Follow these instructions twice, dragging them to the beginning and the end:

 # xcode-build-bump.sh # @desc Auto-increment the build number every time the project is run. # @usage # 1. Select: your Target in Xcode # 2. Select: Build Phases Tab # 3. Select: Add Build Phase -> Add Run Script # 4. Paste code below in to new "Run Script" section # 5. Drag the "Run Script" below "Link Binaries With Libraries" # 6. Ensure that your starting build number is set to a whole integer and not a float (eg 1, not 1.0) # 7. Check the checkbox "Run script only when installing" buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}") buildNumber=$(($buildNumber + 1)) /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}" 

See https://gist.github.com/sekati/3172554

+18
Feb 28 '14 at 10:25
source share

Xcode includes an agvtool command-line agvtool to increase version numbers . Therefore, you do not need to do everything manually using PListBuddy .

xcrun agvtool next-version -all

increases your build number.

xcrun agvtool new-marketing-version 2.0

sets the new visible version number for the user.

See full documentation for more details.

+5
Oct 30 '15 at 11:05
source share



All Articles