合并和分离.a和.framework库

项目中要求接入Adjust的事件集成功能。接入完成后,在提交AppStore的过程中,出现异常:
ERROR ITMS-90087: "Unsupported Architectures. The executable for AAM_iOS_JP.app/Frameworks/AdjustPurchaseSdk.framework contains unsupported architectures '[x86_64, i386]'."
ERROR ITMS-90087: "Unsupported Architectures. The executable for AAM_iOS_JP.app/Frameworks/AdjustSdk.framework contains unsupported architectures '[x86_64, i386]'."
ERROR ITMS-90209: "Invalid Segment Alignment. The app binary at 'AAM_iOS_JP.app/Frameworks/AdjustPurchaseSdk.framework/AdjustPurchaseSdk' does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."
ERROR ITMS-90209: "Invalid Segment Alignment. The app binary at 'AAM_iOS_JP.app/Frameworks/AdjustSdk.framework/AdjustSdk' does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."
ERROR ITMS-90125: "The binary is invalid. The encryption info in the LC_ENCRYPTION_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple's linker."
WARNING ITMS-90080: "The executable 'Payload/AAM_iOS_JP.app/Frameworks/AdjustPurchaseSdk.framework' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables. For more information refer to Technical Q&A QA1788 - Building a Position Independent Executable in the iOS Developer Library."
WARNING ITMS-90080: "The executable 'Payload/AAM_iOS_JP.app/Frameworks/AdjustSdk.framework' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables. For more information refer to Technical Q&A QA1788 - Building a Position Independent Executable in the iOS Developer Library."

根本原因,是framework中,包含[x86_64, i386]架构,这是AppStore不允许的:
真机:armv7,armv7s,arm64架构
模拟器:i386,x86_64

最终,通过lipo命令,将[x86_64, i386]架构抽离出来。

[一、.Framework库合并与拆分]

.framework库与.a库类似,只是.framework库可以包含Header和Bundle,其实相当于一个目录,所以操作的是里面的库文件,而不是xxx.framework文件

例如有两个不同架构的库

IJKMediaFramework_x86_64.framework

IJKMediaFramework_arm64.framework

查看.framework信息

lipo -info IJKMediaFramework_arm64.framework/IJKMediaFramework

input file IJKMediaFramework_arm64.framework/IJKMediaFramework is not a fat file

Non-fat file: IJKMediaFramework_arm64.framework/IJKMediaFramework is architecture: arm64

合并库

lipo -create IJKMediaFramework_x86_64.framework/IJKMediaFramework IJKMediaFramework_arm64.framework/IJKMediaFramework -output IJKMediaFramework

得到通用的库IJKMediaFramework替换到IJKMediaFramework_x86_64.framework/IJKMediaFramework,这时候IJKMediaFramework_x86_64.framework就是通用framework

抽取出arm64库

lipo IJKMediaFramework_x86_64.framework/IJKMediaFramework -thin x86_64 -output IJKMediaFramework

[二、.a库合并与拆分]

例如有两个不同架构的库liba-arm64.a,liba-i386.a

查看库的架构信息

lipo -info liba-arm64.a

input file liba-arm64.a is not a fat file

Non-fat file: liba-arm64.a is architecture: arm64

如果静态库支持多种架构,那么就是一个fat file

合并两个库

lipo -create liba-arm64.a liba-i386.a -output liba.a

合并成liba.a到当前目录

抽取出arm64库

lipo liba.a -thin arm64 -output liba-arm64.a

你可能感兴趣的:(合并和分离.a和.framework库)