将 s.frameworks 'XCTest' 添加到 podspec dyld 时出错:库未加载:rpath/XCTest.framework/XCTest

Error when adding s.frameworks 'XCTest' to podspec dyld: Library not loaded: rpath/XCTest.framework/XCTest

我有一个使用 XCTest 框架的 CocoaPod。要将 XCTest 导入 pod,我将 s.frameworks = 'XCTest' 添加到 .podspec 文件。

我现在可以将 XCTest 导入 pod 类,但是在尝试 运行 示例项目时,我收到以下错误:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest

Referenced from: /Developer/CoreSimulator/Devices/DEVICE_UUID/data/Containers/Bundle/Application/ID/TestPod_Example.app/Frameworks/TestPod.framework/TestPod

Reason: image not found

找到解决方案,在 podspec 中添加 XCTest 框架时,请确保仅在 中将其添加到您的 UITesting 和测试目标Podfile.. 这是因为XCTest不能在开发目标上运行,只能在测试目标上。

在您的 Podfile

target 'MyProjectTestTarget' do
   pod 'PodFramework that includes XCTest as a dependency'
end