Flutter项目迁移至Mac Mini M2后Xcode编译失败:找不到FirebaseCore模块
解决Flutter迁移到Mac Mini M2后Xcode编译"No such module 'FirebaseCore'"问题
项目此前在虚拟机运行正常,迁移至Mac Mini M2后,Xcode编译报错“No such module 'FirebaseCore'”,但Android Studio可正常编译运行。以下是针对性解决方案:
1. 彻底清理依赖与缓存
执行以下命令清空旧依赖和缓存,重新拉取适配arm64架构的资源:
flutter clean rm -rf ios/Pods rm ios/Podfile.lock rm -rf ~/Library/Caches/CocoaPods rm -rf ios/Runner.xcworkspace flutter pub get cd ios && pod install --repo-update
2. 修正Podfile配置
原Podfile中use_frameworks!与use_modular_headers!的顺序及单独配置FirebaseCore的方式可能引发冲突,修改为:
# Uncomment this line to define a global platform for your project platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' project 'Runner', { 'Debug' => :debug, 'Profile' => :release, 'Release' => :release, } def flutter_root generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) unless File.exist?(generated_xcode_build_settings_path) raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" end File.foreach(generated_xcode_build_settings_path) do |line| matches = line.match(/FLUTTER_ROOT\=(.*)/) return matches[1].strip if matches end raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" end require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) flutter_ios_podfile_setup target 'Runner' do use_frameworks! :linkage => :static use_modular_headers! flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) # target 'RunnerTests' do # inherit! :search_paths # end end post_install do |installer| installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) end end
核心调整:使用use_frameworks! :linkage => :static适配M2架构,统一开启use_modular_headers!,移除单独指定FirebaseCore的modular headers配置。
3. 检查Xcode架构设置
- 打开Xcode的Runner项目,进入Build Settings
- 找到
Architectures,设置为Standard Architectures (arm64) - 找到
Excluded Architectures,Debug模式下若包含arm64则移除,Release模式保持默认
4. 更新Firebase依赖版本
确保pubspec.yaml中Firebase相关依赖为最新兼容版本,例如:
dependencies: flutter: sdk: flutter firebase_core: ^2.24.2 # 其他Firebase依赖同步更新
执行flutter pub upgrade完成依赖更新。
5. 重新构建项目
- 关闭Xcode,重新打开
ios/Runner.xcworkspace(注意不要打开xcodeproj) - 执行Product > Clean Build Folder,再尝试编译
内容的提问来源于stack exchange,提问作者Tahir
相关产品推荐
相关产品推荐

