swift - 如果使用模拟器,从 Xcode 和 xcodebuild 运行 xctests 会失败 - dyld : Library not loaded: @rpath/libswiftSwiftOnoneSupport. dylib 问题 - print()

标签 swift xcode cordova xcodebuild

当我从 Xcode 运行测试或从终端执行此命令时,我遇到了一个奇怪的行为:

xcodebuild test -scheme '<MY_APP>' 

尽管在第二种情况下测试成功,但两种情况下的测试都成功了,但是显然我需要指定一个测试设备。当我尝试这样做并使用 -destination 标志执行相同的命令时:

xcodebuild test -scheme '<MY_APP>' -destination "platform=iOS Simulator,name=iPhone XS,OS=latest"

我收到这个错误:

e2019-02-18 18:39:22.625 xcodebuild[36312:791798] Error Domain=IDETestOperationsObserverErrorDomain Code=6 "Early unexpected exit, operation never finished bootstrapping - no restart will be attempted" UserInfo={NSLocalizedDescription=Early unexpected exit, operation never finished bootstrapping - no restart will be attempted, NSUnderlyingError=0x7f8a38637410 {Error Domain=IDETestOperationsObserverErrorDomain Code=5 "Test runner exited before starting test execution." UserInfo={NSLocalizedDescription=Test runner exited before starting test execution., NSLocalizedRecoverySuggestion=If you believe this error represents a bug, please attach the result bundle at /Users/<MY_USER>/Library/Developer/Xcode/DerivedData/<MY_APP>/Logs/Test/<MY_APP>-2019.02.18_18-37-12-+0100.xcresult}}} Generating coverage data... Generated coverage report: /Users/<MY_USER>/Library/Developer/Xcode/DerivedData/<MY_APP>-fbdolvrdfafpjbenwwqzgnlfkpoa/Logs/Test/Test-<MY_APP>.02.18_18-37-12-+0100.xcresult/1_Test/action.xccovreport Testing failed: <MY_APP>.app (36589) encountered an error (Early unexpected exit, operation never finished bootstrapping - no restart will be attempted. (Underlying error: Test runner exited before starting test execution.)) ** TEST FAILED **

其他要提及的事情:这是一个 Cordova 应用程序。 native iOS 部分是用 Objective-C 编写的。但我正在使用一些用 Swift 编写的库。我需要 xcodebuild 来测试我服务器上的应用程序。任何可能导致此问题的建议?同样,当我第一次在没有目标标志的情况下执行命令时,代码签名是成功的,但是当我使用目标标志执行它时,它是空的:

    CodeSign /Users/<MY_USER>/Library/Developer/Xcode/DerivedData/<MY_APP>-fbdolvrdfafpjbenwwqzgnlfkpoa/Build/Products/Debug-iphonesimulator/<MY_APP>.app/PlugIns/<MY_APP>Tests.xctest (in target: <MY_APP>Tests)
    cd /Users/<MY_USER>/projects/my_project/
    export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate

Signing Identity:     "-"

更新:

我可以通过某种方式找到问题的原因,这是一个众所周知的错误:

    dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib
Referenced from: /Users/<MY_USER>/Library/Developer/CoreSimulator/Devices/5AEAA313-0C65-49D8-BC20-DCC9994719C4/data/Containers/Bundle/Application/48DC52C0-4BC6-45ED-9AEE-A0E1F5C8BA1B/P2P-1-<MY_APP>.app/Frameworks/<REQUIRED_FRAMEWORK>.framework/<REQUIRED_FRAMEWORK>

您可能认为从现在开始,解决方案是简单直接的,但事实并非如此。

最佳答案

因为这个库加载错误指向一个框架,我被卡住了......

我试过这些: dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib

Xcode - Bundle format unrecognized, invalid, or unsuitable

References to Removed Framework in project.pbxproj File

Always Embed Swift Standard Libraries 已在应用程序中设置为 YES,但我不确定它是否已设置为 YES给定的框架也是如此。

总而言之,解决方案来自这个问题:dyld: Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib

LuisCien 建议在代码中的任何地方专门使用 print() 会以某种方式强制加载 libswiftSwiftOnoneSupport.dylib,问题就会消失。

测试现在正在运行,虽然我很好奇为什么这个 ,,hack,, 有效。

此外,只有当我尝试使用带有 Xcode 的模拟器或 xcodebuild 运行它时,测试才会失败。

关于swift - 如果使用模拟器,从 Xcode 和 xcodebuild 运行 xctests 会失败 - dyld : Library not loaded: @rpath/libswiftSwiftOnoneSupport. dylib 问题 - print(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54753039/

相关文章:

Swift 和预制件?

swift - 无法在可编程约束之间切换

objective-c - 如何制作可滚动的 TabBar ...?

iphone - 如何在注释周围添加一个圆作为半径

android - Http 请求仅在发布 Android APK 时失败

swift - 命名元组 - Swift - 如何使用

ios - 带有 TableView 部分页眉和页脚的注释 Controller

ios - 取消关注用户后 TableView 不重新加载数据 swift

cordova - ionic 服务找不到模块 'reflect-metadata'

android - 没有Phonegap服务且没有Internet的Adobe Dreamweaver CS6编译应用程序