xcodebuild archive: set version number and build number
Asked Answered
M

2

5

I'm writing a bash script to archive and export my project so I can send it to iTunes Connect. However, the documentation from the command line is a little confusing. I'm trying to figure out if there's a way to pass a parameter to the xcodebuild command that would set the version number and build number for that archive (similar to how you pass -scheme MyScheme when calling xcodebuild). Anyone done something like this before?

Thanks!

Modlin answered 17/7, 2015 at 1:57 Comment(0)
S
15

You can use this:

/usr/libexec/Plistbuddy -c "Set CFBundleVersion $SBUILD_NUMBER" "$PLIST"
/usr/libexec/Plistbuddy -c "Set CFBundleShortVersionString $BUNDLE_SHORT_VERSION" "$PLIST"

with PLIST is the path to your Info.plist

Sanitation answered 17/7, 2015 at 2:26 Comment(2)
Thanks for this. I am really trying to avoid using fastlane as part of my build process for a project. It is just a XCFramework hosted on a repository and I didn't want to pull in all the ruby baggage.Diarthrosis
Plistbuddy comes with macOS. It is not part of fastlane.Weikert
C
0

I found another way which is safer, without modifying Info.plist directly. Assuming you're using MARKETING_VERSION and CURRENT_PROJECT_VERSION to set CFBundleShortVersionString and CFBundleVersion, respectively.

PBXPROJ_FILE="YOUR_XCODE_PROJECT_FILE/project.pbxproj"
VERSION_NUMBER="WRITE_YOUR_DESIRED_VERSION_NUMBER_HERE"
BUILD_NUMBER="WRITE_YOURDESIDER_BUILD_NUMBER_HERE"

sed -i "" "s/MARKETING_VERSION = .*/MARKETING_VERSION = $VERSION_NUMBER;/g" "$PBXPROJ_FILE"
sed -i "" "s/CURRENT_PROJECT_VERSION = .*/CURRENT_PROJECT_VERSION = $BUILD_NUMBER;/g" "$PBXPROJ_FILE"

reference: How to change build setting versioning in Xcode 11 using script?

Chellean answered 26/9 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.