I have an iOS app that currently use this script in Build Phases
to update bundle version when archive.
#!/bin/bash
buildNumber=$(date +%Y%m%d%H%M%S) /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
Now that I need to add a dependence watchOS app. My watch app is written with SwiftUI
while my iOS app is UIKit
. I'm using Xcode 14.2
.
I also need to have this process of update watch app version to the same as iOS when archive.
After several tried and error,
like,
- using PlistBuddy to update both iOS & watchOS's
info.plist
.
buildNumber=$(date +%Y%m%d%H%M%S)
watchOSPlist=$(path/to/watchOS/plist)
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_PATH"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$watchOSPlist"
This has issue: iOS is archived with correct app version, but watchOS always wrong app version.
- using AgvTool to update both
Plist
andCurrent Project Version
.
buildNumber=$(date +%Y%m%d%H%M%S)
agvtool new-version -all $buildNumber
exit 0
This has issue that the build is always canceled. Exactly same issue here:
Archive in Xcode 4.5 - No errors, but build cancelled
https://discussions.apple.com/thread/5075181
It seems that:
The iOS app takes the version from the
Info.plist
's Bundle Version, while the watchOS app takes the version fromProject Setting
>Build Setting
>Current Project Version
So now I set as bellow:
Set Info.plist
's bundle version
to $(CURRENT_PROJECT_VERSION)
, the just use agvtool as pre-action - archive scheme 's script
buildNumber=$(date +%Y%m%d%H%M%S)
agvtool new-version $buildNumber
exit 0
-all
will modify the plist, so I remove the -all
, it will just modify the project file.
to modify before archive, but the actual result is, it archives first and then change the version later, resulting wrong version in archive.
So what can I do to make this happen?
I expect a script to change the version of both iOS & watchOS to the same number for archiving.