Xcode 10 - UITests - 原因:找不到图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52566702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:49:43  来源:igfitidea点击:

Xcode 10 - UITests - Reason: image not found

iosswiftxcodecocoapodscocoapods-1.6

提问by qunayu

I'm trying to run the UItests for my app but it's crashing as soon as it loads. Here's the error.

我正在尝试为我的应用程序运行 UItests,但它一加载就崩溃了。这是错误。

2018-09-29 16:19:49.577151+1000 xxxUITests-Runner[6007:69633] (dlopen_preflight(/Users/Acc/Library/Developer/Xcode/DerivedData/xxx-bjuwemcifadxhlhgojgfktmmades/Build/Products/Debug-iphonesimulator/xxxUITests-Runner.app/PlugIns/xxxUITests.xctest/xxxUITests): Library not loaded: @rpath/libswiftContacts.dylib
  Referenced from: /Users/Acc/Library/Developer/Xcode/DerivedData/xxx-bjuwemcifadxhlhgojgfktmmades/Build/Products/Debug-iphonesimulator/xxxUITests-Runner.app/PlugIns/xxxUITests.xctest/Frameworks/MapboxGeocoder.framework/MapboxGeocoder
  Reason: image not found)

I'm using CocoaPods(1.6.0.beta.1) to install my frameworks. I'm running Xcode10 with swift 4.2 and IOS 12. Git is used as version control with other developers (Perhaps there're conflicts?).

我正在使用 CocoaPods(1.6.0.beta.1) 来安装我的框架。我正在使用 Swift 4.2 和 IOS 12 运行 Xcode10。Git 用作其他开发人员的版本控制(也许存在冲突?)。

My target app works perfectly, both on a simulator and a real phone, and so does my unit tests. But my UITest target fails as soon as it launches up. This problem happens on both a simulator and a real machine.

我的目标应用程序在模拟器和真实手机上都能完美运行,我的单元测试也是如此。但是我的 UITest 目标一启动就失败了。这个问题在模拟器和真机上都会发生。

There have been many posts on the issue before, but none of them have helped me so far. I've had 2 isolated occurrences before, the first time I've solved by adding dependencies into my pod file for the UITest unit, and the second time by simply removing my target and copy & pasting the classes back into the new target (unconstructive, but last resort). I can do the same this time as well but it's a bit of a waste of time and I'm afraid that this will crop up again in the future.

之前有很多关于这个问题的帖子,但到目前为止没有一个对我有帮助。我之前有过 2 次孤立的事件,第一次我通过将依赖项添加到 UITest 单元的 pod 文件中来解决,第二次通过简单地删除我的目标并将类复制并粘贴回新目标(非建设性,但不得已)。这次我也可以这样做,但这有点浪费时间,而且我担心将来会再次出现这种情况。

This is what I've done so far:

这是我到目前为止所做的:

  1. Clean Xcode builds folder and deleted derived data, IOS device logs, and User Data folders.

  2. Restarted Xcode, Mac, as well as my device and simulators, and recloned repository, and pod update && pod install

  3. Have 'Always embed swift standard libraries' as yes

  4. Checked my Target Application is correct

  5. Made sure offending framework (MapboxGeocoder.framework) is included in Embed Pod Frameworks

  1. Clean Xcode builds 文件夹并删除派生数据、IOS 设备日志和用户数据文件夹。

  2. 重新启动 Xcode、Mac 以及我的设备和模拟器,重新克隆存储库,以及 pod update && pod install

  3. 将“始终嵌入 swift 标准库”设置为是

  4. 检查我的目标应用程序是否正确

  5. 确保有问题的框架 (MapboxGeocoder.framework) 包含在 Embed Pod Frameworks 中

回答by qunayu

So after 5 days, I managed to solve my own problem.

所以5天后,我设法解决了我自己的问题。

I solved it by moving my UITests target out of the scope of my main app in Podfile.

我通过将我的 UITests 目标移出 Podfile 中主应用程序的范围来解决它。

From:

从:

target 'App' do
    use_frameworks!

    pods 'Firebase'

    target 'AppUITests' do
        pods 'Testingpod'
    end
end

To:

到:

target 'App' do
    use_frameworks!

    pods 'Firebase'
end

target 'AppUITests' do
    pods 'Testingpod'
end

回答by Evan

Has found another solution suggested in Cocoapods issue.

在 Cocoapods 问题中找到了另一个建议的解决方案。

As my project is a framework, so the test does not have a host application.

由于我的项目是一个框架,所以测试没有宿主应用程序。

Changed Podfile

更改 Podfile

target 'framework' do
    use_ frameworks!
    pods my_dependencies
    target 'framework_tests' do
        inherit! :search_paths
    end
end

To

target 'framework' do
    use_ frameworks!
    pods my_dependencies
    target 'framework_tests'
end

https://github.com/CocoaPods/CocoaPods/issues/8139

https://github.com/CocoaPods/CocoaPods/issues/8139