iOS开发中使用第三方SDK时经常会遇到一些第三方提供真机和模拟器两套.framework(或.a)文件。但开发者在开发过程中会挺不方便的。这里就来总结一下真机和模拟器的.framework(或.a)文件的合并。
两种库文件的合并方式是一样的, .framework文件的合并稍微有点差别。我们先说.a文件的合并。
运行终端命令:
lipo -create /Users/***/Desktop/ThirdParty/library/Release-iphoneos/libthirdparty.a /Users/***/Desktop/ThirdParty/library/Release-iphonesimulator/libthirdparty.a -output /Users/***/Desktop/ThirdParty/library/Release/libthirdparty.a
就合并成功了。合并完可以验证一下:
lipo -info /Users/***/Desktop/ThirdParty/library/Release/libthirdparty.a
得到如下信息就表示合并成功了。
Architectures in the fat file: /Users/***/Desktop/ThirdParty/library/Release/libthirdparty.a are: armv7 armv7s i386 x86_64 arm64
(其中armv7、armv7s为真机架构, i386为模拟器, x86_64支持32位, arm64支持64位)。
合并.framework文件的方式也基本一样,稍微的区别在于合并的是ThirdPartyAPI.framework下的同名文件ThirdPartyAPI, 然后将合并得到的ThirdPartyAPI文件替换真机或模拟器任一.framework文件下的同名文件就可以了。
终端命令:
lipo -create /Users/***/Desktop/ThirdParty/framework/Release-iphoneos/ThirdPartyAPI.framework/ThirdPartyAPI /Users/***/Desktop/ThirdParty/framework/Release-iphonesimulator/ThirdPartyAPI.framework/ThirdPartyAPI -output /Users/***/Desktop/ThirdParty/framework/Release/ThirdPartyAPI
同样的方式验证:
lipo -info /Users/***/Desktop/ThirdParty/framework/Release/ThirdPartyAPI
得到的结果也是一样:
Architectures in the fat file: /Users/***/Desktop/ThirdParty/framework/Release/ThirdPartyAPI are: armv7 armv7s i386 x86_64 arm64
接下来我们将合并得到的ThirdPartyAPI 替换任一.framework下的ThirdPartyAPI文件, 该.framework就是我们最终需要的.framework文件了, 很简单吧。