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

6,049

Solution 1

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.

Solution 2

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))

Solution 3

There are more options to use the $BUILD_NUMBER variable for build versioning. You can find some examples in Codemagic documentation: https://docs.codemagic.io/building/build-versioning/

Solution 4

In my case, adding:

--build-name=1.0.0 --build-number=$(($BUILD_NUMBER + 100))

didn't affect the build number for my iOS builds, despite it working for Android.

For iOS builds, it was still using the build number from my xCode project.

What worked was to add a pre-build script which would bump the build version on Codemagic's VM:

#!/bin/sh
cd ios
agvtool new-version -all $(($BUILD_NUMBER + 100))

Basically, you'd be running xCode's agvtool, in the ios folder, to update the build number with the one supplied by Codemagic (+100, in my case!).

Share:
6,049
Henry
Author by

Henry

Updated on December 10, 2022

Comments

  • Henry
    Henry over 1 year

    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.