美文网首页
iOS 解决三方库文件冲突的方法

iOS 解决三方库文件冲突的方法

作者: Mr_Lxh | 来源:发表于2021-08-10 15:12 被阅读0次

    最近项目里在集成三方库的时候出现了两个库文件冲突的问题。A库的静态包里 包含了util.o文件 B库是个动态库,也包含了个util.o文件。拆分删掉了A库里的冲突文件并重新生成了A库,解决了问题,记录下解决方案,以作后用。

    步骤流程(libTradingSystem.a为例)

    打开命令行工具:

    1、检查lib架构
    lipo -info /Users/liuxh/Desktop/lib/libTradingSystem.a 
    

    输出结果为:


    image.png
    2、依次拆分libTradingSystem.a架构 (如果有amv7s架构也跟下面操作一样)
    lipo /Users/liuxh/Desktop/libTradingSystem.a -thin armv7 -output /Users/liuxh/Desktop/libTradingSystem_armv7.a
    lipo /Users/liuxh/Desktop/lib/libTradingSystem.a -thin x86_64 -output /Users/liuxh/Desktop/lib/libTradingSystem_x86_64.a
    lipo /Users/liuxh/Desktop/lib/libTradingSystem.a  -thin arm64 output /Users/liuxh/Desktop/lib/libTradingSystem_arm64.a
    

    得到四个文件,如图:


    image.png
    3、选择有冲突的架构,找到架构内的冲突文件
     Ar -t /Users/liuxh/Desktop/lib/libTradingSystem_arm64.a
    

    查询结果如下图所示(冲突文件为arm64架构下的Utils.o文件)


    image.png
    4、移除冲突文件
    Ar -dv /Users/liuxh/Desktop/lib/libTradingSystem_arm64.a Utils.o
    //冲突文件有多个可以这样写
    Ar -dv /Users/liuxh/Desktop/lib/libTradingSystem_arm64.a Utils.o  Utils.o Utils.o Utils.o
    
    5、重新合并静态库
    lipo -creat /Users/liuxh/Desktop/lib/libTradingSystem_arm64.a  /Users/liuxh/Desktop/lib/libTradingSystem_armv7.a  /Users/liuxh/Desktop/lib/libTradingSystem_x86_64.a  -output /Users/liuxh/Desktop/lib/libTradingSystem.a 
    
    6、用新生成的静态库替换掉老库

    至此,整个流程完成。冲突问题解决~

    相关文章

      网友评论

          本文标题:iOS 解决三方库文件冲突的方法

          本文链接:https://www.haomeiwen.com/subject/qgnxbltx.html