【问题标题】:The bundle UITests couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle捆绑包 UITests 无法加载,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包
【发布时间】:2017-03-21 16:49:33
【问题描述】:

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

  • 无法加载捆绑包“UITests”,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包。
  • 库未加载:@rpath/Alamofire.framework/Alamofire。
  • 原因:找不到图片

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

【问题讨论】:

    标签: ios swift travis-ci uitest


    【解决方案1】:

    我能够使用 Xcode 10.1 生成的项目重现此问题。我使用 Swift 4.2 和 CocoaPods 1.10.0 作为依赖管理器。我有以下 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
    

    然后我删除了use_frameworks!,详情请参阅this link

    # 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
    

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

    [!] 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.
    

    这就是我从 MyAppUITests 构建设置中删除这一行的原因:

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

    【讨论】:

    • 如果有多个 pod,语法是什么?
    • @RomanPodymov 我在使用 CocoaPods 1.5.3 时遇到了同样的问题 这是我的 pod 文件,# Uncomment the next line to define a global platform for your project platform :ios, '9.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 'SwiftMessages' pod 'IQKeyboardManager' pod 'AlamofireImage' . pod 'Alamofire' target 'MyAppUITests' do inherit! :search_paths # Pods for testing end end
    • 你好@JibranSiddiQui。尝试从target 'MyAppUITests' 中删除inherit! :search_paths。还是需要保留?
    • 您好,感谢您的评论,@RomanPodymov 我尝试不使用inherit! :search_paths 但无法正常工作,除了这些提及之外,我还有其他 CocoaPods 库。我以前对 uitest 没有任何想法。
    • 你好@JibranSiddiQui。我尝试安装所有这些 pod,但没有错误。你使用的是什么版本的 Xcode?你有 Objective-C 或 Swift 项目吗?
    【解决方案2】:

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

    例子:

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

    【讨论】:

    • 除了使用此解决方案之外,我还发现至少一个对您的测试目标可见的源文件需要具有import <Pod>(在本例中为import Alamofire)才能修复错误。
    【解决方案3】:

    在您的测试中,目标将inherit! :search_paths 更改为inherit! :complete。 请参阅documentation 了解它的作用。

    【讨论】:

      【解决方案4】:

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

      【讨论】:

        【解决方案5】:

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

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

        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
        

        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
        

        最终工作的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
        

        【讨论】:

        • 只有最后一个解决方案也适用于我。我不必移动 use_frameworks!不过,在目标内部,我把它留在了顶部,它工作正常。需要进行所有其他更改。
        【解决方案6】:

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

        【讨论】:

          【解决方案7】:

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

          【讨论】:

            【解决方案8】:

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

            【讨论】:

              【解决方案9】:

              对于使用 Carthage 遇到此问题的任何人,我通过将 /usr/local/bin/carthage copy-frameworks 运行脚本阶段添加到 UITest 目标(而不仅仅是我的主应用程序目标)来解决它,并将框架添加为输入文件。

              【讨论】:

                【解决方案10】:

                ]3

                1. 转到构建阶段
                2. 打开 Copy Pods Resources 并复制路径
                3. 粘贴您从 Copy Pods Resources 复制的路径并使用框架更改标签名称资源
                4. 清理和构建
                5. 运行您的 UITestsFile

                【讨论】:

                • 问题没有提到他们使用 Cocoapods
                • 你在使用carthage时发生了什么,错误的答案。
                【解决方案11】:

                解决我的问题的方法是执行以下步骤: 1) 从 pod 文件中删除 UITests 目标。 最初,我在 pod 文件中有以下内容:

                target 'XUITests' do
                    inherit! :search_paths   
                end
                

                2) 分解 pod(使用 pod deintegrate)

                3) 安装 pod(使用 pod install)

                4) 清理您的项目并运行该项目或您的 UITest

                【讨论】:

                • 但是如果您需要在项目中进行 UI 测试怎么办?
                【解决方案12】:

                就我而言,只需删除 inherit! :search_paths 而不更改文件结构或复制任何 pod 即可解决我的问题。

                【讨论】:

                  【解决方案13】:

                  我看到了答案,但没有解释所以决定发布我的。

                  问题是 UI 测试在控制主应用程序的单独应用程序中执行,因此它不能使用主应用程序的框架,因此如果您只是使用 Cocoapods 继承框架的路径,UI 测试应用程序将在启动时崩溃。

                  要解决此问题,您需要将框架实际复制到 UI 测试应用或更新您的 Podfile:

                  use_frameworks!
                  target 'App' do
                    pod 'Alamofire'
                  
                    target 'App_UnitTests' do
                      inherit! :search_paths
                  
                      pod 'Quick'
                      pod 'Nimble'
                    end
                  end
                  
                  target 'App_UITests' do
                    pod 'Alamofire'
                  end
                  

                  【讨论】:

                    【解决方案14】:

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

                    出现此特定错误:

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

                    我必须嵌入框架

                    【讨论】:

                      【解决方案15】:

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

                      当我尝试运行UI Testing Bundle 来测试Framework 时,我遇到了这个问题

                      解决方法很简单:

                      Build Phases -> + -> New Copy Files Phase -> <select a framework> -> Destination Frameworks 
                      

                      因此生成&lt;UI_Testing_Bundle_name&gt;-Runner.app

                      【讨论】:

                      • 这对我有用。我的 UI 测试包没有加载,它没有识别 xcframework。这样做很有效。谢谢!
                      【解决方案16】:

                      对我来说,错误是在构建 UITests 时。 解决方案: Target 使用了错误的 iOS 版本,我将其替换为与测试 Target 相同的版本,一切正常!!

                      【讨论】:

                        【解决方案17】:

                        对我来说,这个问题是由于我从一个框架中引用了 UIKit 类的扩展中的一个属性,而该框架没有在引用它的文件中导入。通过不使用该属性来修复。我不确定它为什么首先编译 - 这应该是编译时错误,而不是运行时错误。

                        【讨论】:

                          【解决方案18】:

                          就我而言,只需选择“我的 Mac”而不是“我的 Mac (Mac Catalyst)”即可运行测试。

                          【讨论】:

                            【解决方案19】:

                            尝试将应用目标的每个 pod 复制到 UI 测试目标。 2019 年有效。

                            【讨论】:

                              【解决方案20】:

                              如果您实际上使用的是 Cocoapods,您可能只需要运行“pod install”,构建设置就会自动更新。

                              【讨论】:

                                猜你喜欢
                                • 2019-12-12
                                • 1970-01-01
                                • 1970-01-01
                                • 1970-01-01
                                • 2016-04-14
                                • 1970-01-01
                                • 1970-01-01
                                相关资源
                                最近更新 更多