RSSAmplifier

Roland Leth — Tech blog · Feb 19, 2020

Sync build versions between targets

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

I've been working for a while on a new project (stay tuned!) which has a watch app. Up until now I used a script that automatically increases the build number of the app, based on the value in `Info.plist`:

I've been working for a while on a new project (stay tuned!) which has a Watch app. Up until now I used a script that automatically increases the build number of the app, based on the value in Info.plist:

buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"

This works really well, the only problem with Watch targets is that the build number has to be the same for all targets. First idea was to just add this build script to all targets, which might work well, but it just felt wrong.

Xcode offers a build setting called CURRENT_PROJECT_VERSION, which exists at the project level. If you go in each target and delete this setting (if it exists), it means each target will inherit the value found at the project level.

Step 1 accomplished: a single source of truth.

Step 2: automating it. I replaced the PlistBuddy script above with the much simpler one below, added as a build phase on the main app's target:

NEW_VERSION=$(($CURRENT_PROJECT_VERSION + 1)) ❶
xcrun agvtool new-version $NEW_VERSION ❷

What this does is it first reads the current version and adds 1 to it (❶), it then passes it to xcrun's agvtool to be set as the new version (❷).

I think it's much simpler and more elegant this way, even for a single target.

Read on roland.leth.ro

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.