方法:
使用 .a 創(chuàng)建
A_FILE_1="./ext/intel/libXXX.a"
A_FILE_2="./ext/apple/libXXX.a"
# Set the path to the output XCFramework bundle
OUTPUT_DIR="./XXX.xcframework"
rm -rf $OUTPUT_DIR
# Create the output directory if it doesn't exist
mkdir -p $OUTPUT_DIR
# Generate the XCFramework bundle
xcodebuild -create-xcframework \
-library $A_FILE_1 \
-library $A_FILE_2 \
-output $OUTPUT_DIR
使用 .framework 創(chuàng)建
xcodebuild -create-xcframework \
-framework path/to/FrameworkA.framework \
-framework path/to/FrameworkB.framework \
-output output_directory
坑:
為了讓使用 intel 和 m1 芯片的同學(xué)都能使用模擬器或真機(jī), 我們需要兩個(gè) .a: intel.a ( iphoneos arm64 + simulator x86_64 ), apple.a ( simulator arm64 ), 然后使用 xcodebuild 命令創(chuàng)建 xcframework
但是升級到 XCode 15 之后, 同樣的文件, 同樣的命令, 卻報(bào)錯(cuò)了:
error: binaries with multiple platforms are not supported
各種嘗試, 搜索, 最終找到了解決辦法:

image.png
刪除上面紅框中的設(shè)置, XCode 15 在 intel 電腦上可以創(chuàng)建所有我們需要的 .a 文件 ( iphoneos arm64 + simulator x86_64 + simulator arm64 ), 不再需要在 m1 電腦上創(chuàng)建 .a
最后, 使用 xcodebuild 創(chuàng)建 xcframework 成功