M2 MacBook Air搭建Flutter环境编译报错:iOS部署版本不兼容
解决方案
1. 统一依赖的iOS最低部署版本(正规解决amplify_core版本冲突)
手动修改缓存内的amplify_core部署版本不属于长久方案,推荐在Flutter项目的ios/Podfile中添加post_install钩子,强制所有Pods依赖的最低部署版本与项目保持一致:
post_install do |installer| installer.pods_project.targets.each do |target| # 统一设置所有依赖的最低iOS版本为11.0,与项目匹配 target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' end # 针对Amplify系列依赖的额外兜底处理(若统一设置不生效时启用) if target.name.start_with?('amplify_') target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' end end end end
添加完成后执行以下命令重新安装依赖:
cd ios pod deintegrate pod install cd .. flutter clean flutter run
2. 解决M2芯片上x86_64模拟器编译问题
M2芯片原生架构为arm64,报错显示针对x86_64编译,说明存在架构兼容问题,可通过以下方式解决:
方法一:在Podfile中添加架构配置
在ios/Podfile的target 'Runner' do区块内补充:
post_install do |installer| installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end end
方法二:修改Xcode项目设置
- 执行
open ios/Runner.xcworkspace打开Xcode - 选中Runner项目,进入Build Settings
- 搜索
Excluded Architectures,在Debug、Release的模拟器配置中添加arm64 - 同时在Pods项目的Build Settings中重复上述操作
方法三:用Rosetta运行Xcode(可选)
右键点击Launchpad中的Xcode,选择Get Info,勾选Open using Rosetta,重启Xcode后再编译,Xcode会以x86_64兼容模式运行,适配旧依赖架构。
验证
完成设置后,执行flutter run -d "iPhone SE (3rd generation)",即可正常编译并启动应用。
内容的提问来源于stack exchange,提问作者buttonsrtoys
相关产品推荐
相关产品推荐

