App Center 上的 Flutter iOS 构建失败并显示错误:“无效的 Podfile 文件:Generated.xcconfig 必须存在

Tar*_*eem 10 ios flutter visual-studio-app-center

我刚刚按照此处文章将我的应用程序设置为在 App Center 上构建。

尽管 Android 版本在 App Center 上构建和部署良好,但我在 iOS 构建中遇到错误,如下面构建输出的摘录所示:

==============================================================================
Task         : CocoaPods
Description  : Install CocoaPods dependencies for Swift and Objective-C Cocoa projects
Version      : 0.151.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/cocoapods
==============================================================================
[command]/usr/local/lib/ruby/gems/2.6.0/bin/pod --version
1.9.1
[command]/usr/local/lib/ruby/gems/2.6.0/bin/pod install --repo-update

[!] Invalid `Podfile` file: Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first.

 #  from /Users/runner/runners/2.165.2/work/1/s/bdstories/ios/Podfile:51
 #  -------------------------------------------
 #      unless File.exist?(generated_xcode_build_settings_path)
 >        raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
 #      end
 #  -------------------------------------------
##[error]The process '/usr/local/lib/ruby/gems/2.6.0/bin/pod' failed with exit code 1
##[error]The 'pod' command failed with error: The process '/usr/local/lib/ruby/gems/2.6.0/bin/pod' failed with exit code 1
##[section]Finishing: Pod install
##[section]Starting: Xcode build (signed)
Run Code Online (Sandbox Code Playgroud)

我的构建脚本是:

#!/usr/bin/env bash
# Place this script in project/ios/.

# Fail if any command fails.
set -e

# Debug log.
set -x
cd ..

git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH

flutter channel beta
flutter doctor

echo "Installed flutter to `pwd`/flutter"

# Build the app.
flutter build ios --release --no-codesign
Run Code Online (Sandbox Code Playgroud)

我确实添加了flutter pub get错误中提到的,但这并没有什么区别。还值得注意的是,当我在本地 Xcode 中进行构建时,构建工作正常。我还可以毫无问题地将构建的存档部署到 Testflight。这只是我遇到问题的 App Center 构建过程。

我现在有点迷茫,找不到有关如何解决此问题的任何信息。我也是 CI/CD 的新手,所以感谢任何帮助!

更新

我还尝试将以下内容添加到脚本中以强制 App Center 运行与我的本地机器相同版本的 Cocoapods,但这对错误没有影响。

sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.9.1
pod setup
Run Code Online (Sandbox Code Playgroud)

小智 3

我对克隆后脚本执行了此操作,并且它有效:

#!/usr/bin/env bash
#Place this script in project/ios/

echo "Uninstalling all CocoaPods versions"
sudo gem uninstall cocoapods --all --executables

COCOAPODS_VER=`sed -n -e 's/^COCOAPODS: \([0-9.]*\)/\1/p' Podfile.lock`

echo "Installing CocoaPods version $COCOAPODS_VER"
sudo gem install cocoapods -v $COCOAPODS_VER

# fail if any command fails
set -e
# debug log
set -x

pod setup

cd ..
git clone -b beta https://github.com/flutter/flutter.git
export PATH=`pwd`/flutter/bin:$PATH

flutter channel master
flutter doctor
flutter pub get

echo "Installed flutter to `pwd`/flutter"

flutter build ios --release --no-codesign
Run Code Online (Sandbox Code Playgroud)

诀窍似乎是将“如果任何命令失败则失败”部分移至 Pod 重新安装之后