在使用InjectionIII热重载工具时遇到了一个奇怪的问题:Library not loaded: @rpath/libswiftCore.dylib 详细报错信息如下:
Error loading /Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection: dlopen(/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection, 265): Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection
Reason: no suitable image found. Did find:
/usr/lib/swift/libswiftCore.dylib: mach-o, but not built for iOS simulator
大致的意思是热重载的bundle依赖libswfitCore.dylib这个动态库,但是在@rptah下并没有找到libswiftCore.dylib,所以默认找到了/usr/lib/swift/libswiftCore.dylib,但这个mach-o文件是应用于mac的并非iOS simulator。
为什么报错?
因为使用了非Xcode默认自带的模拟器版本,而且指定的模拟器下没有swift的动态库。
自带模拟器的动态库信息
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/swift
非Xcode自带模拟器的存放路径
/Library/Developer/CoreSimulator/Profiles/Runtimes
我们选中其中的一个版本,看看他带有的动态库
/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 11.3.simruntime/Contents/Resources/RuntimeRoot/usr/lib
其下面压根都没有swift文件夹,更无从谈起swift相关的动态库。这就是为何需要使用Xcode自带的模拟器版本。