Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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://stackoverflow.com/a/58164679/7332815 but not working

I can only get correct value from

echo $versionNumber 
echo $buildNumber

but how can I set new value to it?

like image 703
andrew54068 Avatar asked Oct 28 '19 02:10

andrew54068


People also ask

How do I run a script in Xcode?

The best way to assure the script is run automatically is to execute it as a Run Script Build Phase. To do so in Xcode 7: Press the "+" button at the top to add a "Run Script" build phase. Name the new build phase as you see fit, for example "Set build number"

What are Xcode build settings?

Deep dive — Xcode Build Settings. With Xcode build settings we can… | by Prasanna Aithal | Mac O’Clock | Medium With Xcode build settings we can control the build phases in order to generate a product i.e application or custom frameworks. Knowing on these settings will helps us to gain knowledge on how specific task will be performed.

How do I add a script build phase in Xcode?

To do so in Xcode 7: Press the "+" button at the top to add a "Run Script" build phase. Name the new build phase as you see fit, for example "Set build number"

How do I get the current build version of a project?

As long as you set any project's Versioning System to Apple Generic, and give it an initial Current Project Version (the name for the Build Number in the Build Settings) of 1 (under Versioning in your build settings - do it at the Project level, and you only have to do it once, instead of setting it for each Target).


1 Answers

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.

like image 102
andrew54068 Avatar answered Sep 23 '22 09:09

andrew54068