2

我在脚本文件中编写了以下命令,为 iPhoneSimulator 和 iPhoneOS 创建 XCFrameworks,如下所示:

xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive" -sdk 'iphonesimulator' SKIP_INSTALL=NO

xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive" -sdk 'iphoneos' SKIP_INSTALL=NO

xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive/Products/Library/Frameworks/ProjectDiphoneSimulator.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneSimulator.xcframework"

xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive/Products/Library/Frameworks/ProjectDiphoneOS.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneOS.xcframework"

在将其拖放到嵌入式框架和库后,我尝试在项目中使用它

当我以设备为目标运行项目时,它工作正常。但是当我在模拟器上运行它时,它会抛出以下错误:

在为 iOS 模拟器构建时,在/Users/Ron/XCFrameworks/ProjectD.xcframework中找不到库

如果我更改存档和 XCFramework 创建的顺序,如下所示:

xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive" -sdk 'iphoneos' SKIP_INSTALL=NO

xcodebuild archive -scheme "ProjectD" -archivePath "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive" -sdk 'iphonesimulator' SKIP_INSTALL=NO

xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive/Products/Library/Frameworks/ProjectDiphoneOS.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneOS.xcframework"

xcodebuild -create-xcframework -framework "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive/Products/Library/Frameworks/ProjectDiphoneSimulator.framework" -output "/Users/Ron/XCFrameworks/ProjectDiphoneSimulator.xcframework"

它适用于模拟器,而不适用于具有相同错误的设备:

在为 iPhone 构建时,在/Users/Ron/XCFrameworks/ProjectD.xcframework中找不到库

我也将Build Libraries for Distribution设置为Yes。如果我尝试使用不同的目的地创建它们(iPhone 和模拟器的 2 个 XCFrameworks)它正在工作。但这实际上违背了 XCFrameworks 的目的。

我是否遗漏了什么或做错了什么步骤?感谢您提前回答。

4

1 回答 1

2

您需要从两者创建一个.xcframework文件.framework。(这将包括模拟器和设备架构)为此运行一个xcodebuild -create-xcframework命令并传递 2 个不同的 .framework 文件:

xcodebuild
-create-xcframework
-framework "/Users/Ron/Archives/ProjectDiphoneOS.xcarchive/Products/Library/Frameworks/ProjectDiphoneOS.framework"
-framework "/Users/Ron/Archives/ProjectDiphoneSimulator.xcarchive/Products/Library/Frameworks/ProjectDiphoneSimulator.framework"
-output "/Users/Ron/XCFrameworks/ProjectDiphoneOS.xcframework"

当您改为运行 2 个不同xcodebuild -create-xcframework的命令时,您.xcframework将只包含您传递的最后一个.framework文件,该文件用于设备。这就是您的项目无法在模拟器中运行的原因。

于 2020-12-21T08:37:45.637 回答