How to read current app version in Xcode 11 with script - ios

Until Xcode 11, I used a script that reads the current app version (for the AppStore) and help me change the LaunchScreen since we can't use swift for that.
sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"
versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
sed -i .bak -e "/userLabel=\"APP_VERSION_LABEL\"/s/text=\"[^\"]*\"/text=\"v$versionNumber\"/" "$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"
But in Xcode 11 there is a new section inside the project's build settings called Versioning
And CFBundleShortVersionString automatically changed to $(MARKETING_VERSION). Xcode automatically handles that and I don't want to change it manually to an static number and let Xcode do it's work.
So the question is how can I access this new MARKETING_VERSION and set it to my launchScreen label using run script?

Xcode 11/12
In terminal or bash script in your project you can use:
App version
xcodebuild -showBuildSettings | grep MARKETING_VERSION | tr -d 'MARKETING_VERSION =' // will be displayed 1.1.6
Build version
xcodebuild -showBuildSettings | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION =' // will be displayed 7
Or (don't forget to change YouProjectName to your project name):
App version
cat YouProjectName.xcodeproj/project.pbxproj | grep -m1 'MARKETING_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '
Build version
cat YouProjectName.xcodeproj/project.pbxproj | grep -m1 'CURRENT_PROJECT_VERSION' | cut -d'=' -f2 | tr -d ';' | tr -d ' '
Or slower method (Thx Joshua Kaden):
App version
xcodebuild -project YouProjectName.xcodeproj -showBuildSettings | grep "MARKETING_VERSION" | sed 's/[ ]*MARKETING_VERSION = //'
Build version
xcodebuild -project YouProjectName.xcodeproj -showBuildSettings | grep "CURRENT_PROJECT_VERSION" | sed 's/[ ]*CURRENT_PROJECT_VERSION = //'

Couldn't find right answer on the internet, so I started digging.
Version and build numbers are displayed in ./PROJECTNAME.xcodeproj/project.pbxproj as MARKETING VERSION (MV) and CURRENT PROJECT VERSION (CPV).
I used sed to get the numbers. It finds first occurrence of MV or CPV, removes everything except the number, and returns result. In order for this to work, you need to do 2 things:
navigate to projects root folder
change PROJECTNAME to your project's name
Commands:
version_number=`sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./PROJECTNAME.xcodeproj/project.pbxproj`
build_number=`sed -n '/CURRENT_PROJECT_VERSION/{s/CURRENT_PROJECT_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./PROJECTNAME.xcodeproj/project.pbxproj`
Result:
Note: If you have more targets in your workspace with different version and build numbers, this might or might not work for you, because it stops on first occurrence. In that case, good luck :)

You can use it like any other project variable:
sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"
versionNumber="$MARKETING_VERSION"
buildNumber="$CURRENT_PROJECT_VERSION"
sed -i .bak -e "/userLabel=\"APP_VERSION_LABEL\"/s/text=\"[^\"]*\"/text=\"v$versionNumber\"/" "$PROJECT_DIR/$PROJECT_NAME/App/Base.lproj/LaunchScreen.storyboard"

I miss here a solution for multiple targets and configurations:
xcodebuild -target <target> -configuration <configuaration> -showBuildSettings | grep -i 'MARKETING_VERSION' | sed 's/[ ]*MARKETING_VERSION = //'
target: the name of the target
configuration: Release, Debug

If you use Bitrise then the following script will save you:
Extracting App Marketing Version
envman add --key=APP_VERSION_NO --value=`sed -n '/MARKETING_VERSION/{s/MARKETING_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./${PATH_TO_YOUR_PROJECT_XCODEPROJ_FILE}/project.pbxproj`
Extracting App Build Number
Extract the Build Number from xcodeproj file only if you use Apple Generic versioning system otherwise extract the Build Number from the XCode project info.plist file.
Note: The following script extracts the Build Number from the xcodeproj file.
envman add --key=APP_BUILD_NO --value=`sed -n '/CURRENT_PROJECT_VERSION/{s/CURRENT_PROJECT_VERSION = //;s/;//;s/^[[:space:]]*//;p;q;}' ./${PATH_TO_YOUR_PROJECT_XCODEPROJ_FILE}/project.pbxproj`
Printing to console:
envman run bash -c 'echo "App Version: $APP_VERSION_NO"'
envman run bash -c 'echo "App Build No: $APP_BUILD_NO"'
Thanks to the answer by #babac

Most voted answers by now show how to extract the value through sed and further tools in the chain. Thought to provide a (simpler?) solution just through awk.
Just to give a little bit of context, following one-liner shows the culprit row:
xcodebuild -project MyProj/MyProj.xcodeproj -showBuildSettings | awk '/MARKETING_VERSION/ { print }'
# output
MARKETING_VERSION = 0.0.1
Default awk field separator should be the space, and so it's just a matter of extracting the third field (MARKETING_VERSION is first, the equal sign is second):
xcodebuild -project MyProj/MyProj.xcodeproj -showBuildSettings | awk '/MARKETING_VERSION/ { print $3 }'
# output
0.0.1
HTH

How about saving a value to CURRENT_PROJECT_VERSION ? did anyone managed to do this?
I can get the value like
buildNumber=$CURRENT_PROJECT_VERSION
but this doesn't work:
CURRENT_PROJECT_VERSION="" or $CURRENT_PROJECT_VERSION=""
In my case I'm trying to set it to ""
This line doesn't set the CURRENT_PROJECT_VERSION field too
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$appInfoPlist"

If your project is set up to use Apple Generic Versioning then you may use this command:
agvtool what-marketing-version -terse1
More info on how to set up AGV can be found here.

For Node.js: there is xcode package. Example of usage:
const xcode = require('xcode');
const project = xcode.project('ios/PROJECT_NAME.xcodeproj/project.pbxproj').parse(() => {
const config = project.pbxXCBuildConfigurationSection();
const releaseScheme = Object.keys(config).find(key => config[key].name === 'Release');
const version = config[releaseScheme].buildSettings.MARKETING_VERSION;
});
Previously I used the plist package, but with latest xCode changes it became outdated, since I'm not able to extract a version from Info.plist for React Native projects.

I had similar issue and made it work by displaying MARKETING_VERSION itself:
version="$MARKETING_VERSION"
version+=" ("
version+=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $SRCROOT/MyApp/Info.plist`
version+=")"
/usr/libexec/PlistBuddy "$SRCROOT/MyApp/Settings.bundle/Root.plist" -c "set PreferenceSpecifiers:1:DefaultValue $version"

I'm developing a framework with this scenario:
A workspace
A framework target
An aggregate target with 2 external scripts:
one for build a fat framework
other for prepare the release framework
The key is that in XCode 11 the aggregate framework script doesn't get run environment variables for other workspace targets so it's impossible to read the $MARKETING_VERSION from my framework target.
So the solution that works for me has been use PlistBuddy specifying the Info.plist result of the framework target build in this way:
FAT_FRAMEWORK="${SRCROOT}/build/${FRAMEWORK_NAME}.framework"
BUILD_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${FAT_FRAMEWORK}/Info.plist")
VERSION_NUMBER=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${FAT_FRAMEWORK}/Info.plist")

Related

Inconsistent CFBundleShortVersionString value

Using Xcode 11, on the first build after a "clean build folder" the value of CFBundleShortVersionString in Info.plist is properly overriden by a build phase script.
This way, we can override the generated Info.plist with a version number derived from a git tag, say 10.1.2.
Here's the build script :
#!/bin/sh
# Extract the latest tag
describe=`git describe --tags`
# Split by '-' char. The first part is the version number, the remaining part is the build number
version=`echo $describe | cut -d '-' -f1`
build=`echo $describe | cut -d '-' -f2`
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $version" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" || exit 1
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $build" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}" || exit 1
After the second build, the CFBundleShortVersionString value is taken from MARKETING_VERSION inside .pbxproj file. MARKETING_VERSION is a new property added in Xcode11 inside every scheme. Let's say that version number is 999.999.999
On the first debug run, the CFBundleShortVersionString would be 10.1.2. and then 999.999.999 after every succeeding builds. Like I said, if I clean the build folder, the version reverts back to the correct value of 10.1.2.
In Xcode 11 this happens both on the simulator and on a device and was working fine in Xcode 10 and previous versions.

Finding bundle identifier in XCode project using shell script

A Bundle identifier in Info.plist of an Xcode project could have various forms, for e.g.
com.company.$(PRODUCT_NAME:rfc1034identifier)
$(PRODUCT_BUNDLE_IDENTIFIER)
Someone could design their own product bundle identifier for debug, release etc types of build and write a variable against Bundle identifier, e.g. com.company.$(PRODUCT_NAME:rfc1034identifier).$(someRandomVariable)
I want to write a shell script that just reads the bundle identifier properly.
However, if you only know shell script - I know, how to figure out values of variables in $(), but want a shell script that should give me all such variables in the string and then I will have code to figure out their values, post which I will create string back with the variables replaced with values.
function getBundleIdentifier
{
cfBundleIdentifier=${PRODUCT_BUNDLE_IDENTIFIER}
if [ ${#cfBundleIdentifier} -lt 1 ]; then
SOURCE="rfc1034identifier"
cfBundleIdentifier=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "${PROJECT_DIR}/${INFOPLIST_FILE}")
if echo "$cfBundleIdentifier" | grep -q "$SOURCE"; then
echo `eval echo $cfBundleIdentifier``eval echo ${PRODUCT_NAME:rfc1034identifier}`
else
echo `eval echo $cfBundleIdentifier`
fi
else
echo $cfBundleIdentifier
fi
}
This is what I have written, but it does not cover all the cases.
It's very easy, just run this command:
BUNDLE_ID=`xcodebuild -showBuildSettings | grep PRODUCT_BUNDLE_IDENTIFIER`
echo $BUNDLE_ID
you can use this
xcodebuild -project Myproject.xcodeproj \-showBuildSettings | grep PRODUCT_BUNDLE_IDENTIFIER | awk -F ' = ' '{print $2}'
or just consolidated the non-xcode portion into :
xcodebuild……. |
{m,g}awk '$!NF = $(NF=2*/PRODUCT_BUNDLE_IDENTIFIER/)' FS=' = '
To get get the bundle identifier in a shell script, I found this to be the simplest way:
xcodebuild -showBuildSettings | awk -F ' = ' '/PRODUCT_BUNDLE_IDENTIFIER/ { print $2 }'
If your script works currently in a different path, use -project option:
xcodebuild -project Myproject.xcodeproj -showBuildSettings | awk -F ' = ' '/PRODUCT_BUNDLE_IDENTIFIER/ { print $2 }'

Xcode: cannot change version of project

I am not able to change the version of project.
I've tried to change version with Target->General->[Version and Build]
Also, I tried to change version in AppName-info.plist
However, when I archive this project I get build with wrong version
When I am trying submit to Appstore, this error occures
How to solve it? All help will be appreciated!
I solved my problem.
In Target->Build Phases I found script
git=$(sh /etc/profile; which git)
git_release_version=$("$git" describe --tags --always --abbrev=0)
number_of_commits=$("$git" rev-list master | wc -l | tr -d ' ')
target_plist="$TARGET_BUILD_DIR/$INFOPLIST_PATH"
dsym_plist="$DWARF_DSYM_FOLDER_PATH/$DWARF_DSYM_FILE_NAME/Contents/Info.plist"
for plist in "$target_plist" "$dsym_plist"; do
if [ -f "$plist" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $number_of_commits" "$plist"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString ${git_release_version#*v}" "$plist"
fi
done
Then I just removed it.
1.Go to itunes connect
Go to my apps
3.Click on new version
4.Enter the new version number under Store version number
Enter the same version number in xcode,like you did and try to archive the project
I think Build should be integer number ... Version should be 1.x
Build is the pure total number of build that you have made
for example
Version: 1.3
Build: 30

Run a shell script before build in Xcode

I need to adjust my build and version number for my project before build/archiving.
I tried multiple things, but so far to no avail.
I added a target with the script to update the numbers and added that as first dependency to my main target. But because I have multiple dependencies as I have extensions in my app and all dependencies are executed by Xcode in parallel (or at least in random order) this does not work.
I added a pre-action to my scheme with the same result. Xcode is not waiting for my pre-action to complete before continuing with the build (I added a sleep 100 to test).
As I'm altering build numbers it is crucial that the script can complete before anything else is started, but there is also one more side-effect: The build even stops due to the fact that the plist files have been altered while building the related target.
What makes it more difficult is, that I would like to use agvtools to set my version & build number. This obviously starts background processes that are out of my control to alter the plists.
Disclaimer: I have searched for other answers, didn't help.
agvtools just does not work in an Xcode build. It will always stop the build.
What works fine is PlistBuddy, although the setup is not as nice and neat.
I added a Pre-Action to the build in my main scheme to call a new target in my project:
xcodebuild -project "${SRCROOT}/MAIN_APP.xcodeproj" -scheme BuildNumberPreProcess
In the target BuildNumberPreProcess I have a Run Script:
VERSION=$(head -n 1 version.txt)
BUILD=`git rev-list $(git rev-parse --abbrev-ref HEAD) | wc -l | awk '{ print $1 }'`
echo "${VERSION} (${BUILD})"
SCRIPT="${SRCROOT}/CLIENT/Supporting Files/set-version-in-plist.sh"
"${SCRIPT}" "${SRCROOT}/MAIN_APP/Supporting Files/Info.plist" ${VERSION} ${BUILD}
"${SCRIPT}" "${SRCROOT}/EXTENSION/Info.plist" ${VERSION} ${BUILD}
...
set-version-in-plist.h:
#!/bin/sh
# set-version-in-plist.sh
#
# usage:
# set-version-in-plist LIST VERSION BUILD
# LIST: Info.plist path & name
# VERSION: version number xxx.xxx.xxx
# BUILD: build number xxxxx
#
# Location of PlistBuddy
PLISTBUDDY="/usr/libexec/PlistBuddy"
echo "$1: $2 ($3)"
${PLISTBUDDY} -c "Set :CFBundleShortVersionString $2" "$1";
${PLISTBUDDY} -c "Set :CFBundleVersion $3" "$1";
Xcode has command line tools for build/archiving: https://developer.apple.com/library/ios/technotes/tn2339/_index.html
So, you can write shell script that at first runs your script for adjusting build/version number and then runs xcode build/archive as command line tool.

How to auto-increment Bundle Version in Xcode 4?

I am trying to figure out how to have the Bundle version number increment automatically in my Xcode 4 project (for ad-hoc and release builds). I found some scripts online that purport to do this but I am unsure of whether to place them in the "Pre-actions" or "Post-actions". I also am unsure what value I should place in the plist; a number that the script will then change or a variable?
All the options that I have tried thus far do not seem to work so any help would be greatly appreciated.
Below is the most recent script I was attempting to use:
conf=${CONFIGURATION}
arch=${ARCHS:0:4}
# Only increase the build number on Device and AdHoc/AppStore build
if [ $conf != "Debug" ] && [ $conf != "Release" ] && [ $arch != "i386" ]
then
buildPlist=${INFOPLIST_FILE}
buildVersion=$(/usr/libexec/PlistBuddy -c "Print CFBuildVersion" $buildPlist)
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBuildNumber" $buildPlist)
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBuildNumber $buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildVersion.$buildNumber" $buildPlist
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildVersion.$buildNumber" $buildPlist
fi
1, Set CFBundleVersion to 1.0.1 or something like x.x.x
2, Add build phases to run shell script autoVersion.sh
3, save below script named autoVersion.sh
#!/bin/sh
# Auto Increment Version Script
# set CFBundleVersion to 1.0.1 first!!!
# the perl regex splits out the last part of a build number (ie: 1.1.1) and increments it by one
# if you have a build number that is more than 3 components, add a '\.\d+' into the first part of the regex.
buildPlist=${INFOPLIST_FILE}
newVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.\d+\.)(\d+)/$1.($2+1)/eg'`
#echo $newVersion;
/usr/libexec/PListBuddy -c "Set :CFBundleVersion $newVersion" "$buildPlist"
4, run shell: cp autoVersion.sh ~/Documents/ and chmod 777 ~/Documents/autoVersion.sh
5, Build & Enjoy it. :)
perl code from: https://gist.github.com/1436598
You may find the following post helpful:
Auto-Incrementing Build Numbers for Release Builds in Xcodefrom iPhone Development
by Jeff LaMarche
http://iphonedevelopment.blogspot.com/2011/07/auto-incrementing-build-numbers-for.html
The same idea as Alix's answer, but much simpler:
buildNumber=`/bin/date +%Y%m%d%H%M%S`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
Add this as a Run Script item on Build Phases on your Target. This has the advantage of being monotonically increasing as well.
This might help you. I am using it in my projects.
https://gist.github.com/alokc83/5207294
#!/bin/sh
# xcode-build-number-generator.sh
# #desc Automaticvally create build number every time using curent day, month and year
# #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"
#Credits
# sekati#github for intial direction about automatic versioning
# http://www.codinghorror.com/blog/2007/02/whats-in-a-version-number-anyway.html (For unferstanding the Software Versoining)
#Feel free to leave comment or report issues
MONTH=`date | awk '{print $2}'`
case "$MONTH" in
'Jan' )
MONTHNUMBER=1
;;
'Feb' )
MONTHNUMBER=2
;;
'Mar' )
MONTHNUMBER=3
echo "Month is $MONTHNUMBER"
;;
'Apr' )
MONTHNUMBER=4
;;
'May' )
MONTHNUMBER=5
;;
'Jun' )
MONTHNUMBER=6
;;
'Jul' )
MONTHNUMBER=7
;;
'Aug' )
MONTHNUMBER=8
;;
'Sep' )
MONTHNUMBER=9
;;
'Oct' )
MONTHNUMBER=10
;;
'Nov' )
MONTHNUMBER=11
;;
'Dec' )
MONTHNUMBER=12
;;
esac
DATE=`date | awk '{print $3}'`
echo "Date = $DATE"
YEAR=`date | awk '{print $6}'`
echo "Date = $YEAR"
### only uncomment section below if testing the format in terminal
#echo "BuildNumber1 = $MONTH$DATE$YEAR"
#echo "or BUILD NUMBER = $DATE$MONTH$YEAR"
#echo "or BUILD NUMBER = $MONTHNUMBER$DATE$YEAR Format is |Month Number Date Year|"
#echo "or BUILD NUMBER = $DATE$MONTHNUMBER$YEAR format is |Date MonthNumber Year|"
############################
#### Uncomment only one one style or last one will be in effect
#buildNumber=$MONTH$DATE$YEAR
#buildNumber=$DATE$MONTH$YEAR
buildNumber=$MONTHNUMBER$DATE$YEAR
#buildNumber=$DATE$MONTHNUMBER$YEAR
echo "Final Build number is $buildNumber"
## Below command write buildNumber in the property list
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"
For anyone wanting to integrate version incrementing into a command line build script (perhaps for continuous integration), see the following commands:
# cd into the project folder containing the plist
cd /Users/waitea/iOS/E.ON/iOS/trunk/Eon
# grab the version numbers
major_version=$(grep -C 2 CFBundleVersion App-Info.plist | grep -o '[0-9]\+.[0-9]\+.[0-9]\+')
major_version_min=$(echo $major_version | grep -o '[0-9]\+.[0-9]\+\.')
minor_version=$(echo $major_version | grep -o '[0-9]\+$')
# increment the minor version
increment=`expr $minor_version + 1`
incremented_whole_version="$major_version_min$increment"
# replace the build number in the plist using perl
/usr/bin/perl -p -i -e "s/$major_version/$incremented_whole_version/g" App-Info.plist
That will increment the rightmost number in a x.x.x style version number. Tweak the reg-ex's to alter for your convention.
Took me a while so I thought I'd share to give back to the community!
EDIT - I created a continuous integration system that'll do this for you
https://github.com/adamwaite/XcodeProject
I've found that using tiered xcconfigs helps this problem.
Working on complex builds with apps, libraries, and SDKs you have to be able to coordinate not merely build numbers per project, but build number compatibility.
You can make a build management header that is effectively a text file with build iteration numbers (or versioning info i.e. beta, dev, rel) and import it through the xcconfig import chain per project.
At that point you can have a target build script step that will embed your build/versioning info. This is also best done by putting holding text in your plist and running PlistBuddy on your derived file/built file sections. (This way your source control changes are minimal)
If you can write a build execution script that does the necessary build number twiddling (or better yet, use a system like bamboo which creates the file for you), you can keep that separate from your code. Granted, if you need to do it and keep track, you may have to check in the changed build number to allow it to increment.
I've been able as a result of this to maintain build numbers along the line of:
2.0.3 b34 (3473) Where we have a build number and an SVN checkout build point.
(Please no git hazing, I'm old school)
Pre/Post actions are more for Uber notifications or processes:
Email that the build started/failed/ etc
Copy the done project to the done project server.
Everything else works better as a Build Script.
(And as always: make the script phase call an external script file. DON'T push your script into the project, it's hell on source controlling the project file)
Hope this helps.
FWIW - this is what I'm currently using to increase the build number only for release builds (which includes archiving). Works fine under Xcode 5.1.
Just copy/paste the snippet into a Run script build phase directly in Xcode:
buildnum=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$PRODUCT_SETTINGS_PATH")
if [ "$CONFIGURATION" = "Release" ]; then
buildnum=$((buildnum + 1))
echo "Build number updated to $buildnum"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildnum" "$PRODUCT_SETTINGS_PATH"
fi;
If you're using a version system like "x.x.x" you can add this run script. It'll increase the version number (x.x.x+1) every time a new build is made:
if [ "${CONFIGURATION}" != "Debug" ]; then
VERSIONNUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
NEWSUBVERSION=`echo $VERSIONNUM | awk -F "." '{print $4}'`
NEWSUBVERSION=$(($NEWSUBVERSION + 1))
NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F "." '{print $1 "." $2 "." $3 ".'$NEWSUBVERSION'" }'`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $NEWVERSIONSTRING" "${PROJECT_DIR}/${INFOPLIST_FILE}"
fi
I haven't found a great solution for Xcode 10.1. I have modified some scripts to reach the goal. And everything now works fine.
version=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${INFOPLIST_FILE}")
build=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${INFOPLIST_FILE}")
/usr/libexec/PlistBuddy -c "Set :PreferenceSpecifiers:1:DefaultValue ${version}" "${CODESIGNING_FOLDER_PATH}/Settings.bundle/Root.plist"

Resources