Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increment build number of Flutter IOS app when deploying with CodeMagic

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.

like image 936
Henry Avatar asked Feb 03 '23 19:02

Henry


2 Answers

From Codemagic documentation they show you a few options:

Here are some examples of the build arguments you can use to increment the app version. You can enter the build arguments in App settings > Build > Build arguments.

--build-name=2.0.$BUILD_NUMBER --build-number=$(($BUILD_NUMBER + 100))

--build-name=1.0.0 --build-number=$BUILD_NUMBER

--build-number=$(git rev-list HEAD --count)

Add it here:

enter image description here

Please note that the number of builds in BUILD_NUMBER is counted separately for each workflow.

like image 100
Andre Cytryn Avatar answered Feb 06 '23 09:02

Andre Cytryn


This works now, i wrote to Codemagic.io. This is the response:

We provide $BUILD_NUMBER variable to use it for versioning. For instance you can use build arguments like --build-name="1.0.$(($BUILD_NUMBER + 100))" --build-number=$(($BUILD_NUMBER + 100))

like image 44
Niklas Raab Avatar answered Feb 06 '23 08:02

Niklas Raab