【问题标题】:Import Frameworks on Apple SiliconApple Silicon 上的导入框架
【发布时间】: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)

重现步骤:

  1. 新建项目(选择 SwiftUI)
  2. 集成 GooglePlaces 框架(如此处“手动”中所述 --> https://developers.google.com/maps/documentation/places/ios-sdk/start
  3. 在文件中导入“GooglePlaces”
  4. 尝试在 M1 Mac(配置 1)上构建项目
  5. 观察以下错误:
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


    【解决方案1】:

    由于您特别提到您正在尝试在 M1 Mac 上构建 Google Places,现在这是不可能的,因为 GooglePlaces 尚未更新到新的 XCFrameworks,

    您甚至可以在此处查看未解决的问题: https://github.com/googlemaps/google-maps-ios-utils/issues/355

    此外,对于要在 M1 Mac 模拟器上运行的任何框架,它们应该作为 XCFramework 提供,或者您现在可以在物理设备上运行

    或者除了 Google Places 之外,对于其他框架,您可以使用 Carthage 通过使用以下命令将它们作为 xcframework 使用:

    carthage update --use-xcframeworks
    

    【讨论】:

      【解决方案2】:

      在您的项目中转到

      1. Xcode 项目构建设置
      2. 仅将 a​​rm64 添加到“iOS 模拟器”构建的排除架构中。

      【讨论】:

      • 您能解释一下为什么这会修复错误吗?它看起来更像是一种解决方法 - 而不是修复。
      • 我用您的解决方案和以下错误更新了我的问题。