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

将Firebase Crashlytics从CocoaPods转Swift Package后M1 Mac模拟器编译失败

M1 Mac模拟器编译Firebase Crashlytics(Swift Package集成)失败解决方案

问题背景

我已从Podfile移除Crashlytics,改用Swift Package集成。项目在真机上可正常编译,但切换到M1 Mac的iOS模拟器时编译失败,尝试删除Derived文件夹等操作后问题仍未解决。另一使用Intel Mac+Xcode 13.2.1的开发者可正常编译模拟器。无论先编译真机还是模拟器,最终模拟器编译都会出现相同错误。所有目标的Excluded Architectures均设置为arm64,Build Active Architecture=YES。

错误日志如下:

Xcode 13.4.1
Mac: Monterey 13.4

ld: warning: ignoring file .../Build/Products/Debugging-iphonesimulator/FirebaseCrashlytics.o, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-arm64
... (12 others)
ld: warning: ignoring file .../Build/Products/Debugging-iphonesimulator/FirebaseInstallations.o, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-arm64
Undefined symbols for architecture x86_64:
"OBJC_CLASS$_FIRCrashlytics", referenced from:
objc-class-ref in -8e51ce451b9a03f7582a9e76a8faf6a6.o
objc-class-ref in -e71967da3e8b662633c9220e635ffc51.o
"OBJC_CLASS$_FIRApp", referenced from:
objc-class-ref in SSLog-8e51ce451b9a03f7582a9e76a8faf6a6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)


解决步骤

1. 更新Firebase Swift Package版本

旧版本Firebase可能存在M1模拟器架构适配缺陷,先把包更到最新稳定版:

  • 打开Xcode,进入File > Add Packages...
  • 找到已添加的Firebase包,选择更新到最新版本(建议10.0+)

2. 精准配置模拟器架构排除

虽然你已经设置了Excluded Architectures,但要确保是针对模拟器目标:

  • 打开项目设置(Project > Build Settings)
  • 搜索Excluded Architectures,切换到All视图而非Combined
  • 检查Debug-iphonesimulator配置下,所有目标(主App、Swift Package依赖)的该选项都设为arm64

3. 用Rosetta运行Xcode

M1 Mac默认用arm64架构运行Xcode,容易和模拟器x86_64架构冲突:

  • Launchpad找到Xcode,右键选Get Info
  • 勾选Open using Rosetta,重启Xcode后重新编译

4. 清理Swift Package缓存

缓存的旧编译产物可能导致架构不匹配:

  • 打开终端,进入项目目录,执行命令:
    rm -rf .build
    rm -rf ~/Library/Caches/org.swift.swiftpm
    rm -rf ~/Library/Developer/Xcode/DerivedData
    
  • 回到Xcode,选择File > Packages > Reset Package Caches,再重新编译

5. 验证Build Active Architecture设置

确保该选项仅在Debug模拟器配置下为YES:

  • 搜索Build Active Architecture Only
  • 确认Debug-iphonesimulator配置下是YES,Release配置保持NO即可

6. 手动添加模拟器有效架构

如果Valid Architectures选项未显示,手动添加x86_64:

  • 在Build Settings中点击+按钮,添加Valid Architectures
  • 在Debug-iphonesimulator配置下填入x86_64

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 10:40:25