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

修复Apple Silicon Mac上flutter_video_cast致iOS模拟器编译失败问题

问题

在Apple Silicon Mac(M1/M2)的Flutter项目中引入flutter_video_cast包后,无法为arm64架构的iOS模拟器编译,报错如下:

Error (Xcode): In /<path>/ios/Pods/google-cast-sdk-no-bluetooth/GoogleCastSDK-ios-4.6.1_static/GoogleCast.framework/GoogleCast(aligned_new_bca0ac320467a2457b3e306bfed17856.o), building for iOS Simulator, 
but linking in object file built for iOS, 
file '/<path>/ios/Pods/google-cast-sdk-no-bluetooth/GoogleCastSDK-ios-4.6.1_static/GoogleCast.framework/GoogleCast' 
for architecture arm64
  • 若在Xcode项目中排除iOS模拟器的arm64架构,项目可编译,但滚动/惯性功能会失效。
  • 模拟器“获取信息”中无「使用Rosetta打开」选项。

已尝试但无效的方案

  • 复刻flutter_video_cast插件,在其podspec中添加arm64到VALID_ARCHS
  • 从插件podspec中移除VALID_ARCHS配置
  • 在Flutter项目的Podfile中添加以下配置:
config.build_settings['VALID_ARCHS[sdk=iphonesimulator*]'] = 'x86_64 arm64'
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "i386"  

请问如何解决这类「依赖包未适配arm64模拟器,但仍需保留arm64架构编译以保证功能正常」的问题?


解决方案

核心思路是:仅针对google-cast-sdk-no-bluetooth这个依赖包,在模拟器编译时排除arm64架构,其他包保留arm64支持,既解决编译报错,又不影响滚动等功能。

在Flutter项目的ios/Podfile中添加如下post_install钩子:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    # 针对google-cast-sdk-no-bluetooth单独处理架构
    if target.name == 'google-cast-sdk-no-bluetooth'
      target.build_configurations.each do |config|
        if config.name == 'Debug' || config.name == 'Release'
          # 模拟器编译时排除arm64
          config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
        end
      end
    end
  end
end

同时配合Xcode项目设置检查:

  1. 打开iOS项目的Runner.xcworkspace
  2. 选择Runner target -> Build Settings
  3. 搜索Excluded Architectures,确保仅在模拟器SDK下没有全局排除arm64(或保持为空,让Podfile的配置生效)

这样处理后,编译模拟器时只有Google Cast SDK会用x86_64架构,其他依赖和业务代码仍保留arm64支持,既解决编译报错,又不会导致滚动功能失效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 03:52:47