bugsiOS 专题

将use_frameworks!改为use_modular_he

2019-08-20  本文已影响0人  JohnSnow_b20c

问题描述

在SDK私有库开发过程中, 需要依赖一个Adyen支付库, swift的写的, 所以打开了use_frameworks!这个时候项目一切正常.
后面改了需求:所有的库必须打包成静态库然后链接到主程序中, pod从1.5.0开始刚好也支持静态库, 于是注释use_frameworks!, 打开use_modular_headers!

use_modular_headers!
问题1.链接cocos2d的时候出错, 有几个符号找不到
链接cocos2d.a报错

记录下解决这个问题的过程

-framework "Webp"

是YYKit中依赖了Webp.framwork


YYkit

猜测是不是这个和cocos2d.a中的符号产生了冲突, 最终证明是对的, 改为单独集成YY中的组件, 未知符号的报错终于消失😄


拆分组件
问题2.swift 静态库NSClassFromString为nil?

Adyen支付流程异常, 支付也一直失败, 😔看来Adyen这源码写得不支持swift静态库啊
经过断点调试pluginClass为nil, 测试代码也发现34行classB为nil, 原因也出在这

20731565865104_.pic_hd.jpg
但是当经过32行初始化一个CardPlugin类之后, classB正常
20721565865104_.pic_hd.jpg
有好几种情况会导致这样
-force_load ${PODS_CONFIGURATION_BUILD_DIR}/Adyen/libAdyen.a
image.png

👌搞定!!!

问题疑惑(有大佬帮解答写咩)

2个问题说是解决了, 但是本质的原因还是没搞明白

  1. 为什么同时链接webp.framework静态库和cocos2d.a会有冲突, 导致coco2d中的几个符号找不到

  2. 为什么.xcconfig中链接了adyen, 还是需要进行force_load


    image.png

关于-all_load的
Reference:
IMPORTANT: For 64-bit and iPhone OS applications, there is a linker bug that prevents -ObjC from loading objects files from static libraries that contain only categories and no classes.
The workaround is to use the -all_load or -force_load flags. -all_load forces the linker to load all object files from every archive it sees, even those without Objective-C code.
-force_load is available in Xcode 3.2 and later. It allows finer grain control of archive loading. Each -force_load option must be followed by a path to an archive,and every object file in that archive will be loaded.
翻译如下:
引用:
不过在64位的Mac系统或者iOS系统下,链接器有一个bug,会导致只包含有类别的静态库无法使用-ObjC标志来加载文件。变通方法是使用-all_load 或者-force_load标志,它们的作用都是加载静态库中所有文件,不过all_load作用于所有的库,而-force_load后面必须要指定具体的文件。
解释:
这个flag是专门处理-ObjC的一个bug的。用了-ObjC以后,如果类库中只有category分类但是没有类的时候,这些category分类还是加载不进来。
变通方法就是加入-all_load或者-force-load。

但根据CardPlugin的定义, 也不像是上面的那种情况


CardPlugin
上一篇下一篇

猜你喜欢

热点阅读