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

M1设备Flutter macOS应用构建失败求助

解决M1设备上Flutter macOS应用Firebase相关构建失败问题

问题背景

M1设备运行Flutter macOS应用时构建失败,报错指向FirebaseSharedSwift和FirebaseCoreInternal的Swift模块编译失败,但iPhone设备运行正常,pubspec依赖如下:

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.8
  firebase_core: ^3.9.0
  cloud_firestore: ^5.6.0
  flutter_bloc: ^8.1.3
  bloc: ^8.1.3
  firebase_auth: ^5.3.4
  equatable: ^2.0.7
  crypto: ^3.0.6

解决方案

1. 彻底清理缓存与Pods

执行以下命令清理Flutter缓存、macOS端Pods文件:

flutter clean
rm -rf macos/Pods macos/Podfile.lock macos/Runner.xcworkspace
pod repo update
flutter pub get
cd macos && pod install && cd ..

2. 调整Xcode架构配置

打开macos/Runner.xcworkspace,按以下步骤修改:

  • 选中Runner target,进入Build Settings
  • 找到Architectures,设置为Standard Architectures (arm64, x86_64)或直接指定arm64
  • 找到Build Active Architecture Only,Debug模式设为Yes,Release模式设为No
  • 找到Excluded Architectures,确保未排除arm64架构

3. 配置Podfile兼容M1架构

编辑macos/Podfile,在target 'Runner' do代码块之前添加以下内容:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ARCHS[sdk=macosx*]'] = 'arm64'
      config.build_settings['ONLY_ACTIVE_ARCH'] = 'YES'
    end
  end
end

保存后重新执行cd macos && pod install && cd ..

4. 更新Firebase依赖版本

当前使用的Firebase版本可能存在M1 macOS编译兼容问题,尝试升级到最新稳定版:
修改pubspec.yaml中的Firebase依赖:

firebase_core: ^3.10.0
cloud_firestore: ^5.8.0
firebase_auth: ^5.4.0

执行flutter pub get后重新构建应用

5. 确保Xcode工具链为最新版本

打开Xcode检查并安装最新更新,或执行以下命令更新命令行工具:

xcode-select --install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 08:52:13