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

M1 Mac运行Flutter项目至iPhone15 Pro Max模拟器遇错误求助

解决M1 Mac上Flutter运行iPhone 15 Pro Max模拟器的CocoaPods与Xcode错误

第一步:搞定Ruby版本过低问题(适配CocoaPods 1.12.x)

  • 用Homebrew安装rbenv(Ruby版本管理器,避免系统Ruby冲突):
    brew install rbenv
    
  • 将rbenv加入shell配置(根据你使用的shell选择对应命令):
    若使用Zsh:
    echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc
    source ~/.zshrc
    
    若使用Bash:
    echo 'eval "$(rbenv init - bash)"' >> ~/.bash_profile
    source ~/.bash_profile
    
  • 安装满足cocoapods-downloader要求的Ruby 2.7.4:
    rbenv install 2.7.4
    
  • 给当前Flutter项目指定使用该Ruby版本:
    cd 你的Flutter项目根目录
    rbenv local 2.7.4
    

第二步:重新安装Gemfile指定的CocoaPods版本

  • 先卸载所有可能冲突的CocoaPods安装:
    brew uninstall cocoapods
    gem uninstall cocoapods
    
  • 安装Gemfile要求的1.12.x版本:
    gem install cocoapods -v '~>1.12.1'
    
  • 验证版本是否匹配:
    pod --version
    
    输出应为1.12.x系列版本,与Gemfile要求一致。

第三步:修复Xcode的DT_TOOLCHAIN_DIR错误

  • 打开项目ios目录下的Podfile,在文件末尾添加以下代码:
    post_install do |installer|
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          %w[Debug Release].each do |config_name|
            if config.name == config_name
              config.build_settings['LIBRARY_SEARCH_PATHS'] = config.build_settings['LIBRARY_SEARCH_PATHS'].gsub(/DT_TOOLCHAIN_DIR/, 'TOOLCHAIN_DIR')
            end
          end
        end
      end
    end
    
  • 执行Pod安装:
    cd ios
    pod install
    
  • 返回Flutter项目根目录,重新运行项目:
    flutter run
    

额外排查步骤(若上述操作后仍有问题)

  • 清理Flutter和CocoaPods缓存:
    flutter clean
    rm -rf ios/Pods ios/Podfile.lock
    cd ios && pod deintegrate && pod install
    
  • 确保Xcode为最新版本,且首次打开时已接受许可协议(未接受会导致构建失败)。

内容的提问来源于stack exchange,提问作者Cyrus the Great

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 17:02:57