iOS组件化:坑点

1. 当组件继承于第三方库时需修改导入方式

错误引入: #import "AFHTTPSessionManager.h"  
正确引入: #import <AFNetworking/AFHTTPSessionManager.h>

错误引入方式,会在执行如下命令时提示 ”xxx.h“ file not found

pod lib lint xx.podspec

2. 执行 pod spec lint xxx.podspec 时,如果报错无法找到某个依赖库,请添加如下配置参数

pod spec lint xxx.podspec --use-libraries

发布时也需添加如下

pod trunk push xxx.podspec --use-libraries
pod repo push repo_name xxx.podspec --use-libraries

–use-libraries:表示使用静态库或者是framework,这里主要是解决当我们依赖一些framework库后校验提示找不到库的时候
扩展参数
–verbose:有些非语法错误是不会给出错误原因的,这个时候可以使用–verbose来查看详细的验证过程来帮助定位错误。
–allow-warnings:表示允许警告。

3.[!] Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.


pod trunk register '[email protected]' 'liuyongjie' --description='macbook pro'

4.私有库中依赖了静态库.a文件,路径配置正确,仍报错找不到该库,如下:

ld: library not found for -lRangersAppLog-Lite
如上是在导入第三方.a静态库 RangersAppLog-Lite.a 文件后的报错信息
原因:制作私有库时,所依赖静态库命名必须以”lib“开头
解决方案:修改静态库名称为”libRangersAppLog-Lite“。

5. 静态库导入后,依赖库也已配置,编译通过,运行报错如下:

unrecognized selector sent to class 静态库中方法报错找不到该方法
原因:.podspec文件少了 -ObjC 编译配置,并且少bitcode的配置。
解决方案:在.podspec中配置编译项:

s.xcconfig = {
    
     "OTHER_LDFLAGS" => "-ObjC", "ENABLE_BITCODE" => "NO"}

6. 私有库中有些pod依赖库中含有.a静态库,执行 pod install 报错:

[!] The 'Pods-MXStatService_Example' target has transitive dependencies that include statically linked binaries: (/Users/liuyongjie/Documents/233模块&组件/MXStatService/Example/Pods/RangersAppLog/RangersAppLog/Core/libRangersAppLog_Core_ios.a) .a文件无法链接到
原因:podfile文件中指定的是 use_frameworks! ,如果删除此标识,那么frameworks就无法pod了。frameworks与.a静态库不可共存
解决方案:如果私有库组件需依赖.a静态库,又依赖其他framework(如:AFN),那么只能将 .a静态库手动集成了

2020.11.11更新:
直接在.podspec文件中增加 s.static_framework = true 即可。
参考 https://github.com/CocoaPods/CocoaPods/issues/7234

7. 组件依赖组件版本低,如果想更新依赖组件,也需要更新此组件

解决方案:依赖组件中不要写死版本号,应该写 大于多少版本以上的形式,这样就解决了组件更新问题

猜你喜欢

转载自blog.csdn.net/Yj_sail/article/details/104513016