Building for iOS Simulator, but the linked library was built for iOS

我们遇到的问题

image

升级 Xcode 11.4 之后,我们原先的项目无法在模拟器上运行了,因为我们的项目里使用了一些第三方的 SDK,这些 SDK 仅支持在设备上运行,并没有编译对 iOS Simulator 的支持,这下好了,在更新了新的 Xcode 后, 默认已经无法编译链接通过了,报错信息: Building for iOS Simulator, but the linked library was built for iOS。

image

对此,苹果员工 edford 给出的答案是:

Having x86_64 code is not sufficient to distinguish if a binary is intended for the iOS Simulator, a macOS app, or a Mac Catalyst app. Combing built binaries across different destinations (which includes the simulator vs. device binaries) is not a supported combination – there is no Apple platform where ARM code and x86_64 code in the same binary is a correct configuration.

If this is your library, you should have your app build it from source as a dependency of your Xcode project, either through an Xcode target or through Swift Package Manager, so that the right platform information is included based on the build target.

If this is your library but you have a specific reason for it to be pre-compiled, please build it as an XCFramework. XCFrameworks correctly separate out binaries that have the right architectures for the different platforms you target. In addition to instructions on how to build such a XCFramework linked earlier, we have a WWDC talk illustrating it.

If this library is from a framework vendor (either as source or a pre-compiled binary), or you integrate a vendor’s library into your app with a third party dependency manager, please consult with the library vendor or dependency manager for support.

原文链接如下:https://forums.developer.apple.com/thread/130684

Apple 让我们重新编译这些 SDK 以支持 iOS Simulator,如果我们使用的第三方的 SDK,请联系第三方以提供技术支持,这显然不是我们想要的。一方面,一些年代久远的 SDK 已经找不到维护人员,另一方面有些 SDK 仅提供设备的支持也是合理的,毕竟它们本身就无法在模拟器上正确运行,因为它们依赖于硬件设备。

针对这个问题,有人给出了两个解决方案:

方案一

修改Workspaces Setting

File–>Workspaces Setting–>Legacy Build System

image

这个方案是让我们回到旧的编译🧬系统,这不是我们想要的…

方案二 (推荐姿势)

debug模式忽略.a或者framework

build Setting–> EXCLUDED_SOURCE_FILE_NAMES

image

并且在引用地方用宏来判断非模拟器的情况:

  BASH1#if !TARGET_IPHONE_SIMULATOR2#endif

这个方案看起来优雅多了,对,就这么干了!

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 前端资源(一入前端深似海)[https://www.cnblogs.com/cxying93/p/6102768....
    葛亮均阅读 5,288评论 0 2
  • 测试发现bug 开发不认为是bug的时候你怎么办? 说法一: 1、首先明确开发说不是bug的理由。 2、如果是需求...
    忘生__dd4f阅读 4,645评论 0 0
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 12,246评论 16 22
  • 今天感恩节哎,感谢一直在我身边的亲朋好友。感恩相遇!感恩不离不弃。 中午开了第一次的党会,身份的转变要...
    余生动听阅读 13,618评论 0 11

友情链接更多精彩内容