1逮壁、在 Build Settings ~> Build Library for Distribution 設(shè)為YES 狸剃。否則在生成 xcframework時(shí) 會(huì)報(bào)錯(cuò)“ No 'swiftinterface' files found within xx.swiftmodule ”
2、在Build Settings 搜索 Skip Install 并設(shè)置為NO烹玉。否則在歸檔的文件目錄Products下會(huì)沒有輸出文件驰怎。
3、對(duì)項(xiàng)目進(jìn)行歸檔二打,生成framework县忌。可以直接在工程中選擇對(duì)應(yīng)的 scheme 继效,然后在 Product 中選擇 Archive症杏。或者用命令行處理瑞信。xcodebuild archive –help 查看更多使用
eg: 針對(duì) Alamofire 歸檔厉颤,生成framework
首先進(jìn)入到Alamofire 項(xiàng)目目錄下
模擬器:xcodebuild archive -workspace Alamofire.xcworkspace -scheme "Alamofire iOS" -sdk iphonesimulator -archivePath build/simulator
真機(jī):xcodebuild archive -workspace Alamofire.xcworkspace -scheme "Alamofire iOS" –sdk iphoneos -archivePath build/iOS
MacCatalyst:xcodebuild archive -workspace Alamofire.xcworkspace -scheme "Alamofire iOS" -destination 'platform=macOS,arch=x86_64,variant=Mac Catalyst' -archivePath build/mac
Tips:
在歸檔MacCatalyst,生成framework文件時(shí)凡简,-scheme 不應(yīng)該選擇“Alamofire macOS”逼友,因?yàn)樵谏蓌cframework導(dǎo)入到需要使用的工程中時(shí),會(huì)報(bào)一下錯(cuò)誤 “While building for Mac Catalyst, no library for this platform was found in 'Alamofire.xcframework'.” 沒有支持Mac Catalyst的 庫(kù)秤涩。
4帜乞、通過命令行生成xcframework文件。
xcodebuild -create-xcframework –output (xcframework名字) –framework (framework路徑) –framework (framework路徑)筐眷。
eg:針對(duì)Alamofire 生成 xcframework
xcodebuild –create-xcframework -output Alamofire.xcframework –framework Alamofire項(xiàng)目目錄/Alamofire/build/iOS.xcarchive/Products/Library/Frameworks/Alamofire.framework –framework Alamofire項(xiàng)目目錄/Alamofire/build/mac.xcarchive/Products/Library/Frameworks/Alamofire.framework
-framework Alamofire項(xiàng)目目錄/Alamofire/build/simulator.xcarchive/Products/Library/Frameworks/Alamofire.framework
然后就可以在 Alamofire項(xiàng)目目錄下看到Alamofire.xcframework 文件了