Flutter应用Xcode Cloud构建失败:找不到Flutter.xcframework
Xcode Cloud构建Flutter应用报错:找不到Flutter.xcframework
问题详情
使用Xcode Cloud构建Flutter应用时反复触发错误,尝试Flutter官方提供的CI脚本后仍无法解决,核心报错信息:
There is no XCFramework found at '/Volumes/flutter/bin/cache/artifacts/engine/ios/Flutter.xcframework'
当前使用的ci_post_clone.sh脚本
#!/bin/sh # Fail this script if any subcommand fails. set -e # Log function to capture errors log_error() { echo "====> ERROR during: $1" echo "====> Exit Code: $2" exit $2 } # Debug: Print the current working directory and PATH echo "====> Current working directory: $(pwd)" echo "====> PATH: $PATH" # Assuming the current directory is the root of your cloned repo. # Debug: List the contents of the current directory ls -la # Install Flutter using git. Adjust this as necessary for Xcode Cloud. echo "====> Installing Flutter..." git clone https://github.com/flutter/flutter.git --depth 1 -b stable $HOME/flutter export PATH="$PATH:$HOME/flutter/bin" # Check if Flutter was installed successfully flutter --version || log_error "flutter installation" $? # Install Flutter artifacts for iOS echo "====> Precaching Flutter for iOS..." flutter precache --ios || log_error "flutter precache --ios" $? # Install Flutter dependencies echo "====> Installing Flutter dependencies..." flutter pub get || log_error "flutter pub get" $? # Install CocoaPods using Homebrew echo "====> Installing CocoaPods..." HOMEBREW_NO_AUTO_UPDATE=1 brew install cocoapods || log_error "brew install cocoapods" $? # Debug: Check if CocoaPods is available if ! command -v pod &> /dev/null; then log_error "command -v pod" 127 echo "====> Error: CocoaPods could not be found." exit 1 else echo "====> CocoaPods found." fi # Navigate to the Flutter project root directory cd "$(git rev-parse --show-toplevel)" || log_error "git rev-parse --show-toplevel" $? # Install CocoaPods dependencies echo "====> Installing CocoaPods dependencies..." cd ios && pod install || log_error "pod install" $? echo "====> CocoaPods dependencies installed successfully." # Check if Flutter.xcframework exists echo "====> Checking if Flutter.xcframework exists..." if [ ! -d "$HOME/flutter/bin/cache/artifacts/engine/ios/Flutter.xcframework" ]; then echo "====> Error: Flutter.xcframework not found!" log_error "Flutter.xcframework check" 1 else echo "====> Flutter.xcframework found." fi # Run Xcode build command echo "====> Starting Xcode build..." xcodebuild build -workspace ios/Runner.xcworkspace \ -scheme Runner \ -destination 'generic/platform=iOS' \ -derivedDataPath build/ \ -resultBundleVersion 3 \ -resultBundlePath resultbundle.xcresult \ -verbose | tee build_logs.log if [ $? -ne 0 ]; then echo "====> Error: Xcode build failed." exit 1 else echo "====> Xcode build succeeded." fi # Debug: Print success message echo "====> ci_post_clone.sh script completed successfully."
可行解决方案
- 修正Xcode项目中的Flutter路径引用:报错路径指向
/Volumes/flutter/...,但脚本将Flutter安装到$HOME/flutter,需打开Xcode的Runner项目,检查Framework Search Paths和Flutter.xcframework的引用路径,确保指向$HOME/flutter/bin/cache/artifacts/engine/ios/。 - 指定架构执行flutter precache:替换脚本中的
flutter precache --ios为flutter precache --ios --no-android --arm64 --x86_64,确保下载全架构的XCFramework文件。 - 提前设置Flutter路径:将
export PATH="$PATH:$HOME/flutter/bin"移到脚本最开头,避免后续命令因路径未生效导致的异常。 - 检查Xcode Cloud权限:确认构建用户对
$HOME/flutter目录有读写权限,避免权限不足导致XCFramework未正确缓存。 - 指定具体Flutter版本安装:替换克隆命令为指定版本,避免stable分支临时问题,例如:
git clone https://github.com/flutter/flutter.git --depth 1 -b 3.13.0 $HOME/flutter
内容的提问来源于stack exchange,提问作者Edgar J.
相关产品推荐
相关产品推荐

