Xcode 12 兼容问题修复

5,089 阅读2分钟

最近因为一个项目需要获取idfa,而iOS 14推出后不能像以前一样获取idfa了,因此升级了Xcode 12,果不其然,又遇到了一些糟心的问题,下面列举一下踩坑之路。

Xcode 12 模拟器编译报错

问题:升级后打开之前的项目在模拟器上运行不起来,报一下错误:
building for iOS Simulator, but linking in object file built for iOS, xxxx for architecture arm64

或者

library not found for -lAFNetworking

或者

或者

以上问题的原因在Xcode11中 x86_64的机型支持是默认支持的,但Xcode12的时候 苹果推出了arm主机的Mac, 这使得arm主机的Xcode其实就不需要x86_64的默认支持了。 x86_64不默认添加,需要手动添加上才能在Mac上运行模拟器。

解决方案:

以上报错信息Xcode 12以前,我们通过Valid Architectures 来配置支持的机型。

但在Xcode12中, Valid Architectures 这一项被移除掉了,改变成了 VALID_ARCHS的栏目。

我们需要在 VALID_ARCHS 添加上 x86_64的模拟器机型配置 如图:

iOS14模拟器因CoreNFC框架而崩溃,问题如下:

dyld: Library not loaded: /usr/lib/libnfshared.dylib
  Referenced from: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/CoreNFC.framework/CoreNFC
  Reason: no suitable image found.  Did find:
	/usr/lib/libnfshared.dylib: mach-o, but not built for platform iOS-sim
dyld: launch, loading dependent libraries
DYLD_SHARED_CACHE_DIR=/Users/plz/Library/Developer/CoreSimulator/Caches/dyld/19G2021/com.apple.CoreSimulator.SimRuntime.iOS-14-0.18A372
DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
DYLD_LIBRARY_PATH=/Users/plz/Library/Developer/Xcode/DerivedData/HGSmallSpace-aoaicklezglbuvgbuqnbqchibvuq/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
DYLD_PRINT_STATISTICS=1
DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Lib
之前我们的应用程序使用CoreNFC扫描NFC标签,如果不支持NFC,则可以使用扫码。在模拟器中运行也正常。升级Xcode12 之后,在iOS13(或更低版本)中,在模拟器上运行不会有任何问题。但是在Xcode12在iOS14模拟器iPhone11上运行时就出现了上述错误。
通过注释掉代码部分并删除框架链接来删除对CoreNFC框架的任何引用,崩溃消失。分析应该时iOS 14模拟器的问题,只能寄托与Xcode下个版本修复了。

解决方法

在Apple修复这个问题之前从 Xcode 12 beta 6 中复制丢失的 libnfshared,丢失的 libnfshared 可以在该目录下找到:

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/

推荐参考:开发者论坛