ios 无法加载包 UITest,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40480503/
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-08-31 10:43:59  来源:igfitidea点击:

The bundle UITests couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle

iosswifttravis-ciuitest

提问by user2273146

I can't run my test case due to this following errors :

由于以下错误,我无法运行我的测试用例:

  • The bundle “UITests” couldn't be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.
  • Library not loaded: @rpath/Alamofire.framework/Alamofire.
  • Reason: image not found
  • 无法加载包“UITests”,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包。
  • 库未加载:@rpath/Alamofire.framework/Alamofire。
  • 原因:找不到图片

Try searching and solving since two days but couldn't get through this issue can someone please help.

从两天开始尝试搜索和解决,但无法解决此问题,有人可以帮忙。

回答by Roman Podymov

I was able to reproduce this issue with the project generated by Xcode 10.1. I used Swift 4.2 and CocoaPods as a dependency manager. I had the following Podfile:

我能够使用 Xcode 10.1 生成的项目重现此问题。我使用 Swift 4.2 和 CocoaPods 作为依赖管理器。我有以下 Podfile:

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'MyApp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyApp
  pod 'Alamofire', '4.8.1'

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

Then I removed use_frameworks!, see this linkfor more details:

然后我删除了use_frameworks!,有关更多详细信息,请参阅此链接

# Uncomment the next line to define a global platform for your project
platform :ios, '10.0'

target 'MyApp' do

  # Pods for MyApp
  pod 'Alamofire', '4.8.1'    

  target 'MyAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MyAppUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end

I also received some warnings like this:

我也收到了一些这样的警告:

[!] The `MyAppUITests [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-MyApp-MyAppUITests/Pods-MyApp-MyAppUITests.debug.xcconfig'. This can lead to problems with the CocoaPods installation
    - Use the `$(inherited)` flag, or
    - Remove the build settings from the target.

That's why I removed this line from the MyAppUITests build settings:

这就是为什么我从 MyAppUITests 构建设置中删除了这一行:

MyAppUITests build settings

MyAppUITests 构建设置

After that run pod deintegrate && pod installand then the problem disappeared. Probably for projects with more dependencies (like here) you need to use another solution.

在那之后运行pod deintegrate && pod install,然后问题就消失了。可能对于具有更多依赖项的项目(如此),您需要使用另一种解决方案。

回答by Anthony

It's because your pods only apply to your Framework target and no the tests one. Add the tests target to your podfile.

这是因为您的 pod 仅适用于您的框架目标,而不适用于测试目标。将测试目标添加到您的 podfile。

Example :

例子 :

target 'MyFramework' do
  use_frameworks!
  pod 'Alamofire', '~> 4.5'
end

target 'MyFrameworkTests' do
  use_frameworks!
  pod 'Alamofire', '~> 4.5'
end

回答by Shyngys Kassymov

In my case, I needed to separate the UI tests target with use_frameworks!.

就我而言,我需要将 UI 测试目标与use_frameworks!.

Moving the UI tests target from nested structure to its own will not help, if you specified use_frameworks!globally somewhere in the top of the Podfile.

如果您use_frameworks!Podfile顶部的某处全局指定了 UI 测试目标,那么将 UI 测试目标从嵌套结构移动到它自己的结构将无济于事

The Podfilewith error (original):

有错误的Podfile(原始):

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

target 'MyProject' do
  pod 'R.swift', '~> 5.0'
  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end

  target 'MyProjectUITests' do
    inherit! :search_paths
  end
end

The Podfilewith error (first try to fix):

有错误的Podfile(首先尝试修复):

platform :ios, '10.0'

inhibit_all_warnings!
use_frameworks!

def shared_pods
  pod 'R.swift', '~> 5.0'
end

target 'MyProject' do
  shared_pods

  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end
end

target 'MyProjectUITests' do
  shared_pods
end

The final working Podfile:

最终的工作Podfile

platform :ios, '10.0'

inhibit_all_warnings!

def shared_pods
  pod 'R.swift', '~> 5.0'
end

target 'MyProject' do
  use_frameworks!

  shared_pods

  pod 'Moya/RxSwift', '~> 12.0'
  # and other pods

  target 'MyProjectTests' do
    inherit! :search_paths

    pod 'iOSSnapshotTestCase', '~> 6.0'
  end
end

target 'MyProjectUITests' do
  shared_pods
end

回答by Samu?l

Check that the deployment target in your UITest target Build Settings is set to the same as the host application you are trying to test. In my case, I added the UITesting target later on, and it created it with a default of deployment target iOS 12. If you then try to run the UITest on iOS lower than 12, it gave me the error mentioned in the question.

检查 UITest 目标构建设置中的部署目标是否设置为与您尝试测试的主机应用程序相同。就我而言,我稍后添加了 UITesting 目标,并使用默认部署目标 iOS 12 创建了它。如果您随后尝试在低于 12 的 iOS 上运行 UITest,则会出现问题中提到的错误。

回答by Martin O'Shea

I had to add the location of my frameworks to Runpath search Path under targets>mytestTarget>Build Settings>Runpath Search Path

我必须将我的框架的位置添加到目标>mytestTarget>Build Settings>Runpath Search Path 下的 Runpath 搜索路径

回答by Rem-D

In your tests target change inherit! :search_pathsto inherit! :complete. See the documentationfor what this does.

在您的测试中,目标更改inherit! :search_pathsinherit! :complete. 请参阅文档了解它的作用。

回答by catanore

This error happened to me when I added a framework to the project (that's a framework itself, too), and tried to run the tests. I made it optional instead of required, and the tests succeeded. enter image description here

当我向项目添加一个框架(这也是一个框架本身)并尝试运行测试时,发生了这个错误。我将其设为可选而不是必需,并且测试成功。 在此处输入图片说明

回答by YMonnier

Switching to legacy build system fixed thi issue with Xcode 10.

切换到旧版构建系统修复了 Xcode 10 的这个问题。

回答by Mocha

Xcode 11.2 using Apollo framework within another framework. Instead of changing to optional/required, I fixed it by setting to embed.

Xcode 11.2 在另一个框架中使用 Apollo 框架。我没有更改为可选/必需,而是通过设置为嵌入来修复它。

With this specific error:

有了这个特定的错误:

The bundle “XXX” couldn't be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle. Library not loaded: @rpath/Apollo.framework/Apollo

无法加载包“XXX”,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包。库未加载:@rpath/Apollo.framework/Apollo

I had to embed the framework

我必须嵌入框架

enter image description here

在此处输入图片说明

回答by user2273146

1

1

2[![3]3

2[![3] 3

  1. Go To Build Phases
  2. Open Copy Pods Resources and copy the path
  3. Paste the path that you have copied from Copy Pods Resources and change tag name resources with frameworks
  4. Clean and Build
  5. Run your UITestsFile
  1. 转到构建阶段
  2. 打开 Copy Pods Resources 并复制路径
  3. 粘贴你从 Copy Pods Resources 复制的路径,并使用 frameworks 更改标签名称资源
  4. 清洁和构建
  5. 运行你的 UITestsFile