lipo 无法生成fat lib 同时支持arm64架构的真机和模拟器

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  [-framework ...] -output 
xcodebuild -create-xcframework -library  [-headers ] [-library  [-headers ]...] -output 

OPTIONS:
-archive                  Adds a framework or library from the archive at the given . Use with -framework or -library.
-framework           Adds a framework from the given .
                                When used with -archive, this should be the name of the framework instead of the full path.
-library             Adds a static or dynamic library from the given .
                                When used with -archive, this should be the name of the library instead of the full path.
-headers                  Adds the headers from the given . Only applicable with -library.
-debug-symbols            Adds the debug symbols (dSYMs or bcsymbolmaps) from the given . Can be applied multiple times. Must be used with -framework or -library.
-output                   The  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  [-framework ...] -output 

合并.a静态库, 同时指定库和头文件

xcodebuild -create-xcframework -library  [-headers ] [-library  [-headers ]...] -output 

观察一下结果

➜  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

你可能感兴趣的:(lipo 无法生成fat lib 同时支持arm64架构的真机和模拟器)