测试反馈iOS12以下手机上安装Xcode14打的包闪退,iOS12+正常
调试后发现,崩溃日志是dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib
Reason: image not founds
搜索后发现,开发者社区中有此问题的记录,xcode14:Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib,解决方案是:
If you are building your app with Xcode 14 or Xcode 14.0.1, your app will crash on older OS versions, including while building and testing directly from Xcode, as well as after submitting the app to the App Store. The OS versions affected include iOS 11 - 12.1, macOS 10.13 - 10.14.3, as well as watchOS and tvOS versions from the same time frame. To work around the crash when building with Xcode 14, add -Wl,-weak-lswiftCoreGraphics (substituting other library names for swiftCoreGraphics if appropriate for your crash) to the Other Linker Flags build setting.
即添加-Wl,-weak-lswiftCoreGraphics到Build Settings中的Other Linker Flags中。
注意1
然而需要注意的是,假如项目有多个Target,如果添加在Target中,就要针对每个Target都要添加一次,很是麻烦,所以可以直接在PROJECT下的Build Settings中添加。
注意2
在项目中添加了-Wl,-weak-lswiftCoreGraphics到Other Linker Flags之后,编译运行发现还是会崩溃,还是报错,而且是第三方SDK报的,这说明三方SDK也需要这样设置
因为项目中有些库没有用到swiftCoreGraphics,比如一些OC的三方库,或者非UI的库,所以还是要改,需要区分添加。针对项目中Swift类型的UI相关的库,添加这个编译选项,其他的不添加,哪个报错加哪个,最终示例如下:
need_otherlinkerflags_frameworks = ['ObjectMapper', 'HandyJSON', 'YXChainTool', 'YXKitSwift', 'Closures', 'JXSegmentedView', 'SKPhotoBrowser', 'SnapKit', 'TCKit']
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f < 10.0
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] ='10.0'
end
# Xcode14,iOS12以下闪退
if need_otherlinkerflags_frameworks.include?(target.name)
config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -Wl,-weak-lswiftCoreGraphics'
end
# 适配Xcode14打包证书问题
config.build_settings['CODE_SIGN_IDENTITY'] = ''
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
# 适配M1芯片模拟器不能运行问题
config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
end
end
end
pod install后,编译运行,就搞定了
Build Successed