为什么在创建 XCFramework 时出现此错误?:为 iOS 模拟器构建时,在路径

时间:2020-12-21 08:30:41

标签: ios swift xcframework

我在脚本文件中编写了以下命令,为 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

中找不到任何库

我也将构建分发库设置为。如果我尝试使用不同的目的地(iPhone 和模拟器的 2 个 XCFrameworks)创建它们,它就可以工作。但这实际上违背了 XCFrameworks 的目的。

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

1 个答案:

答案 0 :(得分:1)

您需要从 .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 文件,该文件用于设备。这就是您的项目无法在模拟器中运行的原因。