You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Xcode Cloud中使用特定Flutter版本(如3.19.6)而非最新版本?

在Xcode Cloud中指定特定Flutter版本的方法

要在Xcode Cloud环境中使用指定的Flutter版本(如3.19.6)而非默认最新版,可通过以下两种常见方式实现:

方法一:直接在CI脚本中安装指定版本

Xcode Cloud会在代码克隆完成后执行项目根目录下的ci_post_clone.sh脚本,你可以通过这个脚本替换默认的Flutter版本:

  1. 在项目根目录创建ci_post_clone.sh文件,添加以下内容:
#!/bin/bash
# 移除Xcode Cloud默认安装的Flutter(避免版本冲突)
brew uninstall --force flutter

# 克隆指定版本的Flutter仓库(--depth 1 减少下载体积)
git clone https://github.com/flutter/flutter.git -b 3.19.6 --depth 1 $HOME/flutter

# 将指定版本的Flutter路径加入环境变量
echo "export PATH=\"\$HOME/flutter/bin:\$PATH\"" >> $HOME/.zshrc
source $HOME/.zshrc

# 验证安装的版本是否正确
flutter --version
  1. 给脚本添加执行权限(本地操作后提交到仓库):
chmod +x ci_post_clone.sh
  1. 将ci_post_clone.sh提交到Git仓库,Xcode Cloud在构建时会自动执行该脚本切换版本。

方法二:使用FVM(Flutter Version Management)管理版本

如果你的项目已经用FVM管理Flutter版本,可在CI脚本中配置FVM来切换到指定版本:

  1. 在项目根目录的ci_post_clone.sh中添加以下内容:
#!/bin/bash
# 安装FVM
brew install fvm

# 安装指定的Flutter版本
fvm install 3.19.6

# 设置当前项目使用该版本
fvm use 3.19.6

# 验证版本
fvm flutter --version
  1. 同样给脚本添加执行权限并提交到仓库。

注意事项

  • 确保ci_post_clone.sh文件被正确提交到Git仓库,Xcode Cloud才能找到并执行它。
  • 部分Xcode Cloud环境默认使用zsh,若遇到环境变量不生效的情况,可检查是否配置了正确的rc文件(如.zshrc)。

内容的提问来源于stack exchange,提问作者Abdelrahman Tareq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 01:02:40