I am unable to increment the build number of my Flutter app automatically when I deploy it using CodeMagic (https://codemagic.io/) which is owned by Nevercode.
I followed the steps described on this page: https://developer.nevercode.io/docs/incrementing-ios-app-version.
The script they suggest is this:
DSYM_INFO_PLIST="${DWARF_DSYM_FOLDER_PATH}/${DWARF_DSYM_FILE_NAME}/Contents/Info.plist"
buildNumber=$NEVERCODE_BUILD_NUMBER
stringLength=${#buildNumber}
if [ $stringLength -ne 0 ]; then
echo "Updating build number to $buildNumber"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
if [ -f "$DSYM_INFO_PLIST" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUMBER" "$DSYM_INFO_PLIST"
fi
else
echo "Missing build number, skip updating"
fi
After I add this script in Xcode, I get this error:
Running pod install... 34.3s
Running Xcode build...
├─Assembling Flutter resources... 6.1s
└─Compiling, linking and signing... 6.9s
Xcode build done. 30.3s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
=== BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
/Users/macbook/Library/Developer/Xcode/DerivedData/Runner-hdgyskbygbvchfagqudvhwidlraa/Build/Intermediates.noindex/Runner.build/Debug-iphoneos/Runner.build/Script-3590602C2
2484D000061C91A.sh: line 15: syntax error: unexpected end of file
Command /bin/sh failed with exit code 2
Could not build the precompiled application for the device.
Could someone shed some light on how to properly increment the build number of an IOS app when deploying with Codemagic? Should it be a script run in Xcode's build phases or a command added into the build steps of Codemagic workflow?
Ideally, it should not increment whenever I run the app with flutter run
but when I deploy it to App Store Connect.