lipo 可以将不同架构(arm64,armv7, x86_64)的库合并为一个一个。
之前iOS真机架构有两个(arm64, armv7)
iOS模拟器架构有两个(x86_64, i386)
可以用lipo命令将多个架构合并到一个库文件里面。
现在iOS真机架构有两个(arm64, armv7)
iOS模拟器架构有三个(x86_64, i386, arm64)
使用lipo合并架构的时候,开始报错了
➜ products git:(master) ✗ lipo -create iphoneos/arm64/lib/libx264.a iphonesimulator/arm64/lib/libx264.a -output libx264.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: iphoneos/arm64/lib/libx264.a and iphonesimulator/arm64/lib/libx264.a have the same architectures (arm64) and can't be in the same fat output file
一个fat库只能包含一个arm64架构,m1芯片的模拟器是arm64架构,iphone真机的架构也是arm64架构,无法合并到同一个fat库。
解决办法: 使用xcframework
➜ products git:(master) ✗ xcodebuild -create-xcframework -help
USAGE:
xcodebuild -create-xcframework -framework <path> [-framework <path>...] -output <path>
xcodebuild -create-xcframework -library <path> [-headers <path>] [-library <path> [-headers <path>]...] -output <path>
OPTIONS:
-archive <path> Adds a framework or library from the archive at the given <path>. Use with -framework or -library.
-framework <path|name> Adds a framework from the given <path>.
When used with -archive, this should be the name of the framework instead of the full path.
-library <path|name> Adds a static or dynamic library from the given <path>.
When used with -archive, this should be the name of the library instead of the full path.
-headers <path> Adds the headers from the given <path>. Only applicable with -library.
-debug-symbols <path> Adds the debug symbols (dSYMs or bcsymbolmaps) from the given <path>. Can be applied multiple times. Must be used with -framework or -library.
-output <path> The <path> to write the xcframework to.
-allow-internal-distribution Specifies that the created xcframework contains information not suitable for public distribution.
-help Show this help content.
同时支持framework和.a
静态库合并
合并framework
xcodebuild -create-xcframework -framework <path> [-framework <path>...] -output <path>
合并.a
静态库, 同时指定库和头文件
xcodebuild -create-xcframework -library <path> [-headers <path>] [-library <path> [-headers <path>]...] -output <path>
观察一下结果
➜ products git:(master) ✗ xcodebuild -create-xcframework -library iphoneos/libx64.a -headers iphoneos/arm64/include -library iphonesimulator/libx264.a -headers iphonesimulator/arm64/include
-output libx264.xcframework
➜ products git:(master) ✗ ls
iphoneos iphonesimulator libx264.xcframework
➜ libx264.xcframework git:(master) ✗ ls
Info.plist ios-arm64_armv7 ios-arm64_x86_64-simulator
➜ libx264.xcframework git:(master) ✗ cd ios-arm64_armv7
➜ ios-arm64_armv7 git:(master) ✗ ls
Headers libx64.a
➜ ios-arm64_armv7 git:(master) ✗ cd Headers
➜ Headers git:(master) ✗ ls
x264.h x264_config.h