# 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. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0) | |
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}" |
# xcode-version-bump.sh | |
# @desc Auto-increment the version number (only) when a project is archived for export. | |
# @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. Check the checkbox "Run script only when installing" | |
# 6. Drag the "Run Script" below "Link Binaries With Libraries" | |
# 7. Insure your starting version number is in SemVer format (e.g. 1.0.0) | |
# This splits a two-decimal version string, such as "0.45.123", allowing us to increment the third position. | |
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}") | |
NEWSUBVERSION=`echo $VERSIONNUM | awk -F "." '{print $3}'` | |
NEWSUBVERSION=$(($NEWSUBVERSION + 1)) | |
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F "." '{print $1 "." $2 ".'$NEWSUBVERSION'" }'` | |
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $NEWVERSIONSTRING" "${PROJECT_DIR}/${INFOPLIST_FILE}" |
This comment has been minimized.
This comment has been minimized.
Thanks !! Its really awesome. Just the same I was looking. Works as charm. Just wondering do I have to set $2 by myself. there is no increment thing for that. actually I am not sure when to increase $2. If you can point me in right direction. |
This comment has been minimized.
This comment has been minimized.
These need to be pre-build actions, otherwise Xcode will only copy the updated plist every other build. To do this:
|
This comment has been minimized.
This comment has been minimized.
xcode-build-bump.sh works like a charm! |
This comment has been minimized.
This comment has been minimized.
At Xcode 4.6.3 (4H1503) I got this error:
Seems like |
This comment has been minimized.
This comment has been minimized.
@nebiros, I got the same error and removed |
This comment has been minimized.
This comment has been minimized.
Works like a charm :) |
This comment has been minimized.
This comment has been minimized.
great |
This comment has been minimized.
This comment has been minimized.
Works in Xcode 5 thank you |
This comment has been minimized.
This comment has been minimized.
super simple. thanks! |
This comment has been minimized.
This comment has been minimized.
In Xcode 5, method of adding script have changed. Please update the comments as per instructions given on the following link. |
This comment has been minimized.
This comment has been minimized.
thank you! all good with xcode 5 & 7.1 |
This comment has been minimized.
This comment has been minimized.
thank you ~ running with xcode 5.1.1 & ios 7.1 |
This comment has been minimized.
This comment has been minimized.
Seems like you're reinventing the wheel a little bit here. Why not make use of https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/agvtool.1.html |
This comment has been minimized.
This comment has been minimized.
Edit: I removed the $PROJECT_DIR variable & it worked. Thanks! I'm getting this error: Print: Entry, "CFBundleShortVersionString", Does Not Exist Xcode 5.1.1, iOS 7.0. My Version number is "1.1.14" |
This comment has been minimized.
This comment has been minimized.
works on Xcode 6.1 & iOS 8.2 |
This comment has been minimized.
This comment has been minimized.
avgtool does not support git, or is there a newer version that does? |
This comment has been minimized.
This comment has been minimized.
On Xcode6.3.1, I need to change |
This comment has been minimized.
This comment has been minimized.
Thanks, It's working fine on Xcode 6.4 |
This comment has been minimized.
This comment has been minimized.
Grest tool! |
This comment has been minimized.
This comment has been minimized.
Works like a charm |
This comment has been minimized.
This comment has been minimized.
I've tried using agvtool, but ran into config variable issues. Does someone have a working example of using agvtool in Xcode build settings? |
This comment has been minimized.
This comment has been minimized.
Hi,I wrote a Xcode Team Adding Build Number Shell Script Here: |
This comment has been minimized.
This comment has been minimized.
Thanks, It's working fine on Xcode 6.4 & iOS8.4 |
This comment has been minimized.
This comment has been minimized.
Thanks, it's work well! |
This comment has been minimized.
This comment has been minimized.
good on Xcode 7.1, iOS 9 |
This comment has been minimized.
This comment has been minimized.
This was perfect for me. Albeit I customized mine a little bit to my needs because I wanted date/time. Thought I would share incase someone wanted something like mine. '''Adding run script in build phases that will auto generate a build number, IE: 1511021323 (year, month, day, hour, minute) that will be used in conjunction with HockeyApp releases.''' buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}") |
This comment has been minimized.
This comment has been minimized.
+1 Great! |
This comment has been minimized.
This comment has been minimized.
+100 Excellent |
This comment has been minimized.
This comment has been minimized.
@nebiros +1 for xcode 7.3 |
This comment has been minimized.
This comment has been minimized.
cool! Just what I needed |
This comment has been minimized.
This comment has been minimized.
Cool, i used this to add
Someone knows a better approach? |
This comment has been minimized.
This comment has been minimized.
Thanks! Works on Xcode 8.1 |
This comment has been minimized.
This comment has been minimized.
Brilliant, thank you! |
This comment has been minimized.
This comment has been minimized.
work well. Thank you |
This comment has been minimized.
This comment has been minimized.
Thank you so much ! it worked : ) |
This comment has been minimized.
This comment has been minimized.
Awesome! Worked brilliantly. |
This comment has been minimized.
This comment has been minimized.
Good work! |
This comment has been minimized.
This comment has been minimized.
Work well like charm in Xcode 8.3.2 |
This comment has been minimized.
This comment has been minimized.
I may missed something out when setting up my project, but the above path, |
This comment has been minimized.
This comment has been minimized.
Thanks @cusster that worked for me also |
This comment has been minimized.
This comment has been minimized.
Thanks @cusster! Have a nice day. |
This comment has been minimized.
This comment has been minimized.
Still works in Xcode 9.1 |
This comment has been minimized.
This comment has been minimized.
For Xcode 9 Support: |
This comment has been minimized.
This comment has been minimized.
For Xcode 10 support:
|
This comment has been minimized.
This comment has been minimized.
For us, the script don't update the build number but by changing the script the build number change (code for xcode 10):
|
This comment has been minimized.
This comment has been minimized.
Thanks @jndefosse, I use the commit count as the build number.
|
This comment has been minimized.
This comment has been minimized.
I needed to compare buildNumber with the current value in the plist before updating the plist. If the plist is updated on every build, then the SwiftUI previewer will continually stop: currentNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$PRODUCT_SETTINGS_PATH")
if [ "$buildNumber" -ne "$currentNumber" ] ; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$PRODUCT_SETTINGS_PATH"
fi |
This comment has been minimized.
Thank you! Will test them right now :-)