Flutter应用无法在iOS模拟器启动:配置Podfile平台仍报错
解决CocoaPods自动分配iOS 11.0平台的问题
问题分析
你已经在原生项目Podfile里指定了全局platform :ios, '9.0',但错误依然出现,核心原因是Flutter模块的Runner目标没有明确指定iOS平台版本。加载的podhelper.rb在安装Flutter相关Pods时会自动创建Runner目标,这个目标的平台版本并未被你的全局设置覆盖,因此CocoaPods会默认分配iOS 11.0。
解决方案
修改你的Podfile,在post_install块中添加代码,强制为Runner目标指定iOS平台版本:
Uncomment the next line to define a global platform for your project platform :ios, '9.0' flutter_application_path = '../flutter_module_books/' load File.join(flutter_application_path, '.ios', 'Flutter', 'podhelper.rb') target 'IosBooks' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for IosBooks install_all_flutter_pods(flutter_application_path) end post_install do |installer| flutter_post_install(installer) if defined?(flutter_post_install) # 新增:为Runner目标指定iOS平台版本 installer.pods_project.targets.each do |target| if target.name == 'Runner' target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0' end end end end
后续操作
- 进入iOS项目目录执行以下命令清理并重新安装Pods:
cd ios pod deintegrate pod install
- 重启Xcode或iOS模拟器后重新运行项目。
补充说明
如果你的Flutter SDK版本较新,Flutter可能已不再支持iOS 9.0,此时需要将平台版本调整为11.0或更高(如12.0),同时确保原生项目的部署目标也同步更新。
内容的提问来源于stack exchange,提问作者Elena Epshtein
相关产品推荐
相关产品推荐

