Skip to content

Commit 1db5831

Browse files
authored
docs: Update README.md for Build Version Sync (#275)
1 parent f83924c commit 1db5831

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

.github/assets/build_phases.png

154 KB
Loading

README.md

+23-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,29 @@ This step is optional, this will sync the widget extension build version with yo
4444
In your Runner (app) target go to <kbd>Build Phases</kbd> > <kbd>+</kbd> > <kbd>New Run Script Phase</kbd> and add the following script:
4545
```bash
4646
generatedPath="$SRCROOT/Flutter/Generated.xcconfig"
47-
versionNumber=$(grep FLUTTER_BUILD_NAME $generatedPath | cut -d '=' -f2)
48-
buildNumber=$(grep FLUTTER_BUILD_NUMBER $generatedPath | cut -d '=' -f2)
49-
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$SRCROOT/HomeExampleWidget/Info.plist"
50-
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $versionNumber" "$SRCROOT/HomeExampleWidget/Info.plist"
47+
48+
# Read and trim versionNumber and buildNumber
49+
versionNumber=$(grep FLUTTER_BUILD_NAME "$generatedPath" | cut -d '=' -f2 | xargs)
50+
buildNumber=$(grep FLUTTER_BUILD_NUMBER "$generatedPath" | cut -d '=' -f2 | xargs)
51+
52+
infoPlistPath="$SRCROOT/HomeExampleWidget/Info.plist"
53+
54+
# Check and add CFBundleVersion if it does not exist
55+
/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$infoPlistPath" 2>/dev/null
56+
if [ $? != 0 ]; then
57+
/usr/libexec/PlistBuddy -c "Add :CFBundleVersion string $buildNumber" "$infoPlistPath"
58+
else
59+
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$infoPlistPath"
60+
fi
61+
62+
# Check and add CFBundleShortVersionString if it does not exist
63+
/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$infoPlistPath" 2>/dev/null
64+
if [ $? != 0 ]; then
65+
/usr/libexec/PlistBuddy -c "Add :CFBundleShortVersionString string $versionNumber" "$infoPlistPath"
66+
else
67+
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $versionNumber" "$infoPlistPath"
68+
fi
69+
5170
```
5271

5372
Replace `HomeExampleWidget` with the name of the widget extension folder that you have created.

0 commit comments

Comments
 (0)