lipo 可以將不同架構(gòu)(arm64,armv7, x86_64)的庫合并為一個(gè)一個(gè)。
之前iOS真機(jī)架構(gòu)有兩個(gè)(arm64, armv7)
iOS模擬器架構(gòu)有兩個(gè)(x86_64, i386)
可以用lipo命令將多個(gè)架構(gòu)合并到一個(gè)庫文件里面。
現(xiàn)在iOS真機(jī)架構(gòu)有兩個(gè)(arm64, armv7)
iOS模擬器架構(gòu)有三個(gè)(x86_64, i386, arm64)
使用lipo合并架構(gòu)的時(shí)候,開始報(bào)錯(cuò)了
? 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
一個(gè)fat庫只能包含一個(gè)arm64架構(gòu),m1芯片的模擬器是arm64架構(gòu),iphone真機(jī)的架構(gòu)也是arm64架構(gòu),無法合并到同一個(gè)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.
同時(shí)支持framework和.a靜態(tài)庫合并
合并framework
xcodebuild -create-xcframework -framework <path> [-framework <path>...] -output <path>
合并.a靜態(tài)庫, 同時(shí)指定庫和頭文件
xcodebuild -create-xcframework -library <path> [-headers <path>] [-library <path> [-headers <path>]...] -output <path>
觀察一下結(jié)果
? 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