iOS 使用二进制框架在 M1 Mac 上构建模拟器失败 - "Module compiled with Swift 5.4.2 cannot be imported by the Swift 5.5.1 compiler"

iOS simulator builds fail on M1 Mac with binary framework - "Module compiled with Swift 5.4.2 cannot be imported by the Swift 5.5.1 compiler"

模拟器构建在 Xcode 中失败,其中使用了第 3 方框架并且该框架仅以编译形式提供。

设备构建成功,但在 M1 Mac 上构建模拟器时出现错误:

Module compiled with Swift 5.4.2 cannot be imported by the Swift 5.5.1 compiler

有关 Swift 版本的错误具有误导性;如问题中所述,设备构建工作。只有模拟器构建失败。

实际原因是构建框架时没有使用 M1 模拟器切片,因此 Xcode 无法完成模拟器构建。

框架供应商需要提供包含 x86 和 M1 模拟器切片的更新版本。

解决方法是让 Xcode 创建 X86 模拟器版本。

在项目的 Build Settings 中,为 iOS 模拟器构建指定 x86_64 架构: