在日常開發(fā)中,我們會導入各種各樣的包,有時候會遇到兩個包之間相互沖突。那么在我們不能換包的情況下,只能對包內(nèi)沖突的文件進行更改。我遇到的就是在嵌入unity3D的時候和百度地圖的包有沖突duplicate symbol _fopen_file_func。
我叫杜甫,我很忙.png
一般情況下,出沖突后會有這樣的個錯誤。

警告錯誤
這就需要我們對應的解決了。
- cd進入到相互沖突的一個包內(nèi),查看這個包所支持的模式,以下這個例子只有兩種,還有其他的如: armv7s i386 x86_64
$ cd ~/LibraryConflictExample/XCodeProject/PPAppPlatformKit.framework/
$ lipo -i PPAppPlatformKit //如果是.a文件可以直接跳過上面的不過后面的額文件地址要是拽出來的路徑/LibraryConflictExample/XCodeProject/PPAppPlatformKit.framework/ 這種
Architectures in the fat file: PPAppPlatformKit are: armv7 arm64
- 創(chuàng)建相應的模式對應的包,并將對應的模式文件儲存進去
$ lipo PPAppPlatformKit -thin armv7 -output PPAppPlatformKit.armv7
$ lipo PPAppPlatformKit -thin arm64 -output PPAppPlatformKit.arm64
$ ls -l
total 29496
drwxr-xr-x@ 5 dennis staff 170B 8 23 12:26 Headers/
-rw-r--r-- 1 dennis staff 773B 8 23 12:26 Info.plist
drwxr-xr-x@ 3 dennis staff 102B 7 11 18:32 Modules/
-rw-r--r-- 1 dennis staff 7.2M 8 23 12:26 PPAppPlatformKit
-rw-r--r-- 1 dennis staff 3.7M 8 23 12:26 PPAppPlatformKit.arm64
-rw-r--r-- 1 dennis staff 3.4M 8 23 12:26 PPAppPlatformKit.armv7
drwxr-xr-x@ 6 dennis staff 204B 8 23 12:26 _CodeSignature/
-rw-r--r--@ 1 dennis staff 12K 7 11 18:32 embedded.mobileprovision
- 接下來就是查找里面包含的文件,看是否有錯誤信息里面對應的文件
ar -t 包名.x86_64
2
3
4
5
6
7
8
9
$ ar -t PPAppPlatformKit.armv7
...
ioapi.o
...
$ ar -t PPAppPlatformKit.arm64
...
ioapi.o
...
- 刪除上面警告提示的所有錯誤文件 ar -d -sv 上一步生成的對應的包 刪除的文件,如果你的這個包支持多少種模式,都要刪除里面對應的文件比方支持armv7 就刪除PPAppPlatformKit.armv7對應的文件,若支持armv7s i386 x86_64 等多種,就一個個的對應刪除
2
3
4
5
$ ar -d -sv PPAppPlatformKit.armv7 ioapi.o
d - ioapi.o
ar -d -sv PPAppPlatformKit.arm64 ioapi.o
d - ioapi.o
- 在刪除之后進行文件更新,里面該更改的更改為項目對應的名稱
$ mv PPAppPlatformKit PPAppPlatformKit.original // ?? ???? ??
$ lipo PPAppPlatformKit.armv7 PPAppPlatformKit.arm64 -create -output PPAppPlatformKit
參考鏈接
好了這樣基本就解決了所遇到的包沖突問題。