最近項目里在集成三方庫的時候出現(xiàn)了兩個庫文件沖突的問題。A庫的靜態(tài)包里 包含了util.o文件 B庫是個動態(tài)庫,也包含了個util.o文件。拆分刪掉了A庫里的沖突文件并重新生成了A庫,解決了問題,記錄下解決方案,以作后用。
步驟流程(libTradingSystem.a為例)
打開命令行工具:
1、檢查lib架構(gòu)
lipo -info /Users/liuxh/Desktop/lib/libTradingSystem.a
輸出結(jié)果為:

image.png
2、依次拆分libTradingSystem.a架構(gòu) (如果有amv7s架構(gòu)也跟下面操作一樣)
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、選擇有沖突的架構(gòu),找到架構(gòu)內(nèi)的沖突文件
Ar -t /Users/liuxh/Desktop/lib/libTradingSystem_arm64.a
查詢結(jié)果如下圖所示(沖突文件為arm64架構(gòu)下的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、重新合并靜態(tài)庫
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、用新生成的靜態(tài)庫替換掉老庫
至此,整個流程完成。沖突問題解決~