前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Xcode14编译的APP低版本崩溃

Xcode14编译的APP低版本崩溃

原创
作者头像
莫空9081
发布2022-10-11 09:34:47
3.2K1
发布2022-10-11 09:34:47
举报
文章被收录于专栏:iOS 备忘录iOS 备忘录

背景

测试说iOS 12的手机上安装Xcode14.0.2导出的新包后,打开就崩溃,但是在系统版本高的手机上就没有问题。

<!--more-->

调试后发现,崩溃日志是dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib,具体如下:

dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib Referenced from: /private/var/containers/Bundle/Application/55730273-D9D6-4C42-9335-7A56F92B7F2C/xxx.app/Frameworks/FSPagerView.framework/FSPagerView

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-lswiftCoreGraphicsBuild Settings中的Other Linker Flags中。

这里要注意是添加到Other Linker Flags而不是Other Swift Flags,如果遇到下面的报错,就说明你和我一样,添加到了错误的地方。。。。

Driver threw unknown argument: '-weak-libswiftCoreGraphics' without emitting errors.

注意1

然而需要注意的是,假如项目有多个Target,如果添加在Target中,就要针对每个Target都要添加一次,很是麻烦,所以可以直接在PROJECT下的Build Settings中添加。

注意2

在项目中添加了-Wl,-weak-lswiftCoreGraphicsOther Linker Flags之后,编译运行发现还是会崩溃,还是报错

dyld: Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib Referenced from: /private/var/containers/Bundle/Application/55730273-D9D6-4C42-9335-7A56F92B7F2C/xxx.app/Frameworks/FSPagerView.framework/FSPagerView

Reason: image not founds

仔细看了之后,发现报错中提示的FSPagerView,是CocoaPods三方库,所以找到对应的第三方库,然后在对应库的Build Settings中找到Other Linker Flags,然后添加-Wl,-weak-lswiftCoreGraphics,再运行,发现还是报错,但是换了另一个三方库。。。

针对每个三方库一个个添加,是不可能的,太麻烦不说,每次Pod install之后就需要重新再设置,不是正确的解决办法。

所以有没有可能,在Podfilepost_install添加设置,统一一次性给所有三方库加这个编译设置。当然可以,设置如下:

代码语言:Swift
复制
post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          config.build_settings['OTHER_LDFLAGS'] = '-Wl,-weak-lswiftCoreGraphics'
        end
    end
end

然后编译,发现报错,因为项目中有些库没有用到swiftCoreGraphics,比如OC的三方库,或者非UI的库,所以还是要改,需要区分添加。针对项目中Swift类型的UI相关的库,添加这个编译选项,其他的不添加,最终示例如下:

代码语言:Swift
复制
need_otherlinkerflags_frameworks = ['FSPagerView', 'HandyJSON', 'IQKeyboardManagerSwift', 'JXSegmentedView', 'KDCircularProgress', 'Kingfisher', 'RxSwift', 'PKHUD', 'RxCocoa', 'SnapKit', 'ZLPhotoBrowser']
post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          if need_otherlinkerflags_frameworks.include?(target.name)
            config.build_settings['OTHER_LDFLAGS'] = '-Wl,-weak-lswiftCoreGraphics'
          end
        end
    end
end

Pod install后,编译运行,发现可以正常运行了。再验证一下,非低版本手机上是否受到影响,没有影响,完美。

Done!

参考

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 背景
    • 注意1
      • 注意2
      • 参考
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档