How to change build setting versioning in Xcode 11 using script?
Asked Answered
A

2

15

Since Xcode 11 had change Version to $(MARKETING_VERSION) & Build to $(CURRENT_PROJECT_VERSION)

there are new field in build setting

enter image description here

How can I change this value with script due to

xcrun agvtool new-version

xcrun agvtool new-marketing-version

not work perfectly as it on Xcode 10

I tried this one https://mcmap.net/q/822865/-ios-how-to-upgrade-my-cfbundleversion-and-my-cfbundleshortversionstring-automatically-in-xcode-11-my-old-script-doesn-39-t-work-anymore but not working

I can only get correct value from

echo $versionNumber 
echo $buildNumber

but how can I set new value to it?

Autry answered 28/10, 2019 at 2:49 Comment(0)
A
27

update 2022/08/19

if using fastlane to bumping version

desc "Bump version and build nubmer"
lane :bump_version_and_build_number do |options|
    version_number = options[:version]
    puts version_number
    sh("sed -i '' -e 's/MARKETING_VERSION \\= [^\\;]*\\;/MARKETING_VERSION = #{version_number};/' ../${YOUR_PROJECT_NAME}.xcodeproj/project.pbxproj")
    increment_build_number
end

and just type in commend line

bundle exec fastlane bump_version_and_build_number version:1.0.1


okey I find a solution for myself, and thanks to an friend from meetup.

for Version number enter image description here I used sed -i '' -e 's/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = 3.4.5;/' ${YOUR_PROJECT_NAME}.xcodeproj/project.pbxproj

e.g. sed -i '' -e 's/MARKETING_VERSION \= [^\;]*\;/MARKETING_VERSION = 3.4.5;/' DemoProject.xcodeproj/project.pbxproj

note that this can't work in pre-action of scheme setting

As for Build version enter image description here I used xcrun agvtool new-version xxx

e.g. xcrun agvtool new-version 3.4.5b

you can write these command in Build Phases

enter image description here

the reason I don't use xcrun agvtool new-marketing-version 3.4.5b is because it will write solid number into plist.

And I agree with Manuel's answer in Post

With these I can manage multi-targets' versioning

p.s. If you want to do that to, for example, notificationService target, remember to change version and build number manual at first to make Xcode 11 change the corresponding value to an variable like this enter image description here

or you can make that by edit plist in source code of course.

That's the closest method I achieve to manage multi-target versioning so far.

Autry answered 31/10, 2019 at 4:1 Comment(1)
thanks for this. the regex didn't work for me but this did: sed -i '' -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = $VERSION;/" $PROJECT_PATH/project.pbxproj.Lionellionello
G
4

Following script will set the $MARKETING_VERSION and $CURRENT_PROJECT_VERSION similar to xcode and prepare an archive finally that will also appear inside XCode Organizer.

#!/bin/bash

# Set the version and build numbers
VERSION_NUMBER="2.1.0"
BUILD_NUMBER="29"
APP_NAME="MyApp"
TEAM_ID="ABCDEFGH"

# Set the Xcode project file path
PROJECT_FILE="$APP_NAME.xcodeproj/project.pbxproj"

# Update the MARKETING_VERSION and CURRENT_PROJECT_VERSION values in the project file
sed -i "" "s/MARKETING_VERSION = .*/MARKETING_VERSION = $VERSION_NUMBER;/g" "$PROJECT_FILE"
sed -i "" "s/CURRENT_PROJECT_VERSION = .*/CURRENT_PROJECT_VERSION = $BUILD_NUMBER;/g" "$PROJECT_FILE"

# Set the archive path
ARCHIVE_DATE=$(date +"%Y-%m-%d")
ARCHIVE_TIME=$(date +"%H.%M")
ARCHIVE_FILENAME="$APP_NAME $ARCHIVE_DATE, $ARCHIVE_TIME.xcarchive"
ARCHIVE_PATH="~/Library/Developer/Xcode/Archives/$ARCHIVE_DATE/$ARCHIVE_FILENAME"

# Archive the Xcode project
xcodebuild \
  -scheme "$APP_NAME" \
  -project "$APP_NAME.xcodeproj" \
  -configuration "Release" \
  -destination "generic/platform=iOS" \
  -archivePath "$ARCHIVE_PATH" \
  archive 
Gleaning answered 21/4, 2023 at 6:7 Comment(2)
This is a perfect answer, all others over SO are either outdated or require some additional setup. Even an accepted answer uses shell sed - what makes use of fastlane not needed at allCommixture
Thank you mate. Do you have the same bash script for Android?Nipissing

© 2022 - 2024 — McMap. All rights reserved.