【发布时间】:2026-01-10 04:15:02
【问题描述】:
当我尝试将框架集成到 iOS 应用程序中时,在 M1 MacBook(即 Apple Silicon)上构建会失败,但在 Intel Mac 上不会失败。最新 Xcode 和最新 Xcode Beta 上的默认构建设置会发生这种情况。 错误如下:
ld: building for iOS Simulator, but linking in object file built for iOS, file '/.../testm1/GooglePlaces.framework/GooglePlaces' for architecture arm64
clang: error: linker command failed with exit code 1 (use - v to see invocation)
我尝试检查框架中包含哪些架构,然后我看到以下信息:
命令:
lipo -info GooglePlaces.framework/GooglePlaces
输出:
GooglePlaces.framework/GooglePlaces: Mach-O universal binary with 2 architectures: [x86_64cMach-O 64-bit object x86_64] [arm64]
GooglePlaces.framework/GooglePlaces (for architecture x86_64): Mach-O 64-bit object x86_64
GooglePlaces.framework/GooglePlaces (for architecture arm64): Mach-O 64-bit object arm64
我还尝试使用“文件”进行检查:
命令:
file GooglePlaces.framework/GooglePlaces
输出:
GooglePlaces.framework/GooglePlaces: Mach-O universal binary with 2 architectures: [x86_64cMach-O 64-bit object x86_64] [arm64]
GooglePlaces.framework/GooglePlaces (for architecture x86_64): Mach-O 64-bit object x86_64
GooglePlaces.framework/GooglePlaces (for architecture arm64): Mach-O 64-bit object arm64
两个命令都显示它包含 arm64。
配置:
MacBook Pro。 13'' M1 2020,
16 GB
大苏尔 11.4
Xcode 12.5.1 和 Xcode 13.0(测试版 3)
重现步骤:
- 新建项目(选择 SwiftUI)
- 集成 GooglePlaces 框架(如此处“手动”中所述 --> https://developers.google.com/maps/documentation/places/ios-sdk/start)
- 在文件中导入“GooglePlaces”
- 尝试在 M1 Mac(配置 1)上构建项目
- 观察以下错误:
ld: building for iOS Simulator, but linking in object file built for iOS, file '/.../testm1/GooglePlaces.framework/GooglePlaces' for architecture arm64
clang: error: linker command failed with exit code 1 (use - v to see invocation)
问题:
- 如果我无法控制框架的来源,只能控制构建的框架,这是否可以解决?
- 在给定 .framework 文件的情况下,我如何检查框架是支持 iphonesimulator 的 arm64,还是只支持 iphoneos 的 arm64?
按照建议:
我为任何 ios 模拟器排除了 arm64 - 然后构建成功。 但是:当我想在没有宿主应用程序的情况下测试项目时,会发生以下错误:
2021-07-21 12:07:54.021519+0200 xctest[84732:517962] The bundle “testm1Tests” couldn’t be loaded because it doesn’t contain a version for the current architecture. Try installing a universal version of the bundle.
2021-07-21 12:07:54.021692+0200 xctest[84732:517962] (dlopen_preflight(/.../Build/Products/Debug-iphonesimulator/testm1Tests.xctest/testm1Tests): no suitable image found. Did find:
/.../Library/Developer/Xcode/DerivedData/testm1-bkwdzlmojcaocfabaqfrhjnlzfim/Build/Products/Debug-iphonesimulator/testm1Tests.xctest/testm1Tests: mach-o, but wrong architecture)
Program ended with exit code: 80
解决方法选项:
- 由于并非所有框架都支持 xcframeworks,请使用
Rosetta启动 Xcode。然后,您将不会遇到任何这些错误。我知道这不是最好的解决方法,因为 Apple 可能会在未来的 MacOS 版本中删除Rosetta。
【问题讨论】:
标签: ios swift xcode frameworks apple-m1