Flutter IOS - Keep all targets' versions and build numbers up-to-date

Viewed 323

By default, only the Runner target's version and build number stay up-to-date.

I've had to add another target for a plugin I'm using, and at the moment I have to manually keep its version and build number up-to-date.

The reason I care about it is because App Store keeps warning me everytime I upload a build where the targets' versions and build numbers are not in sync.

How can I keep the second target's version and build number up-to-date automatically as well? I suppose it should somehow be done in the Podfile?

2 Answers

I, too, was facing the same problem and used to manually change the version every-time before archiving.

If you are still facing this issue, I have got a work around for this. You can try adding the below code into build phase of the main Target.

    #!/bin/bash
    buildNumber=$(cut -d'=' -f2 <<< $(cat Flutter/Generated.xcconfig | grep FLUTTER_BUILD_NUMBER))
    buildName=$(cut -d'=' -f2 <<< $(cat Flutter/Generated.xcconfig | grep FLUTTER_BUILD_NAME))
    target1="firstTargetName"
    target2="secondTargetName"
    
    echo "kushal___ $buildNumber"
    echo "kushal___ $buildName"
    
    #/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
    #/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildName" "$INFOPLIST_FILE"
    
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$SRCROOT/$target1/Info.plist"
    /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildName" "$SRCROOT/$target1/Info.plist"
    
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$SRCROOT/$target2/Info.plist"
    /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildName" "$SRCROOT/$target2/Info.plist"

enter image description here

First you should add a new xcconfig file to you project(Version.xcconfig). The xcconfig file should look like this(must override the OTHER_LDFLAGS variable ):

#include "Flutter/Generated.xcconfig"
OTHER_LDFLAGS=

Then set you new targets to use the configuration. enter image description here

Last just set your target info.plist's version and build number to Flutter build name and number. enter image description here

Build your project in flutter, then all the target's version will be just the same as you set in you pubspec.yaml file.

Related