lipo 無法生成fat lib 同時(shí)支持arm64架構(gòu)的真機(jī)和模擬器

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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容