简体   繁体   English

使用 CodeMagic 部署时如何增加 Flutter IOS 应用程序的内部版本号

[英]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.当我使用 Nevercode 拥有的 CodeMagic ( https://codemagic.io/ ) 部署它时,我无法自动增加我的 Flutter 应用程序的内部版本号。

I followed the steps described on this page: https://developer.nevercode.io/docs/incrementing-ios-app-version .我按照此页面上描述的步骤操作: 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:在 Xcode 中添加此脚本后,出现此错误:

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?有人可以阐明在使用 Codemagic 部署时如何正确增加 IOS 应用程序的内部版本号吗? Should it be a script run in Xcode's build phases or a command added into the build steps of Codemagic workflow?它应该是在 Xcode 构建阶段运行的脚本还是添加到 Codemagic 工作流程构建步骤中的命令?

Ideally, it should not increment whenever I run the app with flutter run but when I deploy it to App Store Connect.理想情况下,无论何时运行flutter run的应用程序,但当我将其部署到 App Store Connect 时,它都不应该增加。

This works now, i wrote to Codemagic.io.这现在有效,我写信给 Codemagic.io。 This is the response:这是回应:

We provide $BUILD_NUMBER variable to use it for versioning.我们提供 $BUILD_NUMBER 变量以将其用于版本控制。 For instance you can use build arguments like --build-name="1.0.$(($BUILD_NUMBER + 100))" --build-number=$(($BUILD_NUMBER + 100))例如,您可以使用构建参数,如--build-name="1.0.$(($BUILD_NUMBER + 100))" --build-number=$(($BUILD_NUMBER + 100))

From Codemagic documentation they show you a few options:从 Codemagic文档中,他们向您展示了一些选项:

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:在此处添加:

在此处输入图片说明

Please note that the number of builds in BUILD_NUMBER is counted separately for each workflow.请注意,BUILD_NUMBER 中的构建数量是针对每个工作流程单独计算的。

There are more options to use the $BUILD_NUMBER variable for build versioning.有更多选项可以使用 $BUILD_NUMBER 变量进行构建版本控制。 You can find some examples in Codemagic documentation: https://docs.codemagic.io/building/build-versioning/您可以在 Codemagic 文档中找到一些示例: https ://docs.codemagic.io/building/build-versioning/

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.尽管它适用于 Android,但并没有影响我的 iOS 版本的版本号。

For iOS builds, it was still using the build number from my xCode project.对于 iOS 版本,它仍然使用我的 xCode 项目中的版本号。

What worked was to add a pre-build script which would bump the build version on Codemagic's VM:有效的是添加一个预构建脚本,该脚本会在 Codemagic 的 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!).基本上,您将在ios文件夹中运行agvtoolagvtool ,以使用 Codemagic 提供的版本号更新内部版本号(在我的情况下为 +100!)。

My solution was to set the MARKETING_VERSION (manually) and BUILD_NUMBER_VERSION (dynamically) in pre-build script.我的解决方案是在预构建脚本中设置MARKETING_VERSION (手动)和BUILD_NUMBER_VERSION (动态)。

Basically, the MARKETING_VERSION represents a specific version number of your iOS app, like 1.0.0 and BUILD_NUMBER_VERSION represents the number of a build of MARKETING_VERSION , like 1.0.0.20基本上,MARKETING_VERSION代表你的iOS应用程序的特定版本号,如1.0.0和BUILD_NUMBER_VERSION代表的内部版本号MARKETING_VERSION ,像1.0.0.20

I didn't find in any place how can i catch dynamically the actual MARKETING_VERSION in App Store Connect, so I infer that I need to manually set the version in accordance with the version that is in the process for to be publish in App Store.我在任何地方都没有找到如何在 App Store Connect 中动态捕获实际的MARKETING_VERSION ,因此我推断我需要根据要在 App Store 中发布的版本手动设置版本。

I put this code in my pre-build script:我将此代码放在我的预构建脚本中:

cd $FCI_BUILD_DIR/ios
agvtool new-marketing-version 1.0.0
agvtool new-version -all $(($BUILD_NUMBER))

Remember, the MARKETING_VERSION needs to be the same as the version that is in process in App Store Connect.请记住, MARKETING_VERSION需要与 App Store Connect 中正在处理的版本相同。

I've faced the next issue with Codemagic: at the beginning in Info.plist were ${CURRENT_PROJECT_VERSION} for Bundle Version and ${MARKETING_VERSION} for Bundle Version string (short) and these lines above did not work我遇到了 Codemagic 的下一个问题:在 Info.plist 的开头是 ${CURRENT_PROJECT_VERSION} 表示捆绑版本和 ${MARKETING_VERSION} 表示捆绑版本字符串(短),上面的这些行不起作用

The place to put these lines in Codemagic将这些行放在 Codemagic 中的地方

--build-name=2.0.$BUILD_NUMBER --build-number=$BUILD_NUMBER
--build-name=2.0.$PROJECT_BUILD_NUMBER --build-number=$PROJECT_BUILD_NUMBER

But after I changed to ${FLUTTER_BUILD_NUMBER} and ${FLUTTER_BUILD_NAME} for Bundle Version and Bundle Version string (short) respectively lines above in Codemagic started to do magic, they start to work.但是在我将捆绑版本和捆绑版本字符串(短)分别更改为 ${FLUTTER_BUILD_NUMBER} 和 ${FLUTTER_BUILD_NAME} 之后,Codemagic 上面的行开始发挥作用,它们开始工作。

Shareing this for those looking to grab the tag name from git and inspect it to get the major/minor/patch numbers.与那些希望从 git 获取标签名称并检查它以获取主要/次要/补丁号的人分享此内容。

Pre-build script this goes into the pre-build step before the build section.预构建脚本这进入构建部分之前的预构建步骤。

Pre-build script
Run script before the build phase has started
#! /bin/bash
# https://jon.sprig.gs/blog/post/1175
# https://blog.codemagic.io/build-versioning-with-codemagic/

RE='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'

base="$2"
if [ -z "$2" ]
then
  base=$(git tag 2>/dev/null| tail -n 1)
  if [ -z "$base" ]
  then
    base=0.0.0
  fi
fi

MAJOR=`echo $base | sed -e "s#$RE#\1#"`
MINOR=`echo $base | sed -e "s#$RE#\2#"`
PATCH=`echo $base | sed -e "s#$RE#\3#"`
BUILD_TOTAL=$(git rev-list HEAD --count)

GIT_BUILD_NUMBER=$BUILD_TOTAL
GIT_BUILD_TAG_VER="$MAJOR.$MINOR.$PATCH"
GIT_BUILD_VER_BUILD="$MAJOR.$MINOR.$PATCH+$BUILD_TOTAL"

# First Log the variables for the console. Then output them to the CM_ENV property so code magic can use
# them in the subsequent build steps.
echo "GIT_BUILD_TAG_VER=$GIT_BUILD_TAG_VER"
echo "GIT_BUILD_NUMBER=$GIT_BUILD_NUMBER"
echo "GIT_BUILD_VER_BUILD=$GIT_BUILD_VER_BUILD"

echo "input tag = $base"
echo "GIT_BUILD_TAG_VER=$GIT_BUILD_TAG_VER" >> $CM_ENV
echo "GIT_BUILD_NUMBER=$GIT_BUILD_NUMBER" >> $CM_ENV
echo "GIT_BUILD_VER_BUILD=$GIT_BUILD_VER_BUILD" >> $CM_ENV

echo "standard config is usual --build-name=1.0.\$BUILD_NUMBER --build-number=\$BUILD_NUMBER"
echo "config option A)  --build-name=\$GIT_BUILD_TAG_VER --build-number=\$GIT_BUILD_NUMBER"
echo "config option B)  --build-name=\$GIT_BUILD_VER_BUILD --build-number=\$GIT_BUILD_NUMBER"
echo "Option B may not be supported by Apple."
echo "Output in subsequent build step should look like  --build-name=$GIT_BUILD_TAG_VER --build-number=$GIT_BUILD_NUMBER"

# GIT_BUILD_TAG_VER=2.3.4
# GIT_BUILD_NUMBER=953
# GIT_BUILD_VER_BUILD=2.3.4+953
# input tag = v2.3.4-pre-release
# standard config is usual --build-name=1.0.$BUILD_NUMBER --build-number=$BUILD_NUMBER
# config option A)  --build-name=$GIT_BUILD_TAG_VER --build-number=$GIT_BUILD_NUMBER
# config option B)  --build-name=$GIT_BUILD_VER_BUILD --build-number=$GIT_BUILD_NUMBER
# Option B may not be supported by Apple.
# Output in subsequent build step should look like  --build-name=2.3.4 --build-number=953

Build Step Then in your Build section for android/ios build arguments you can add.构建步骤然后在您的构建部分中,您可以添加 android/ios build arguments。

--flavor dev -t lib/main_dev.dart --build-name=$GIT_BUILD_TAG_VER --build-number=$GIT_BUILD_NUMBER

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM