无法加载包“MyProjectUITests",因为它已损坏或缺少必要的资源.尝试重新安装捆绑包 [英] The bundle “MyProjectUITests” couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle

查看:35
本文介绍了无法加载包“MyProjectUITests",因为它已损坏或缺少必要的资源.尝试重新安装捆绑包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我愿意为我的应用添加单元和 UI 测试.

我第一次成功配置了单元测试,我尝试对 UI 测试做同样的事情.这是我的 Podfile,在添加新的 UI 测试包目标后:

平台:ios,'8.0'使用_框架!禁止所有警告!def shared_pods豆荚螺栓"豆荚分支"吊舱'FBSDKCoreKit'pod 'FBSDKLoginKit'吊舱'FBSDKShareKit'pod 'GoogleAnalytics'pod 'GooglePlaces'豆荚解析"pod 'Toast-Swift'结尾目标我的目标"做shared_pods结尾目标 'MyTargetUITests' 做shared_pods结尾目标 'MyTargetUnitTests' 做shared_pods结尾

但是,当我尝试运行自动创建的 MyProjectUITests 测试用例时,它只包含基本设置,甚至没有 @testable import MyProject:

import XCTest类 MyProjectUITests:XCTestCase {覆盖 func setUp() {continueAfterFailure = falseXCUIApplication().launch()}}

我收到此错误:

<块引用>

正在运行测试...无法加载包MyProjectUITests",因为它已损坏或缺少必要的资源.尝试重新安装捆绑包.

(dlopen_preflight(/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/MyProjectUITests):Library not loaded.swiftonrpath/Supportlibdylibdyonrpath

引用自:/private/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/Frameworks/Toast_Swift.framework/Toast_Swift

原因:找不到图片)

怎么了?感谢您的帮助.

EDIT :有关信息,当我从我的 UI 测试目标中删除 Toast_swift pod 并让它只在我的应用和单元测试目标中使用时,它工作正常.

解决方案

查看这个问题 在 cocoapods github 问题跟踪器上.

我仍然有点困惑为什么这会成为一个问题,但是使用此脚本将 ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 设置为 YES 为我解决了这个问题.

post_install 做 |installer|installer.pods_project.targets.each 做 |target|target.build_configurations.each 做 |config|# 这可以解决 Xcode 10 中引入的单元测试问题.# 我们只将它应用到 Debug 配置以避免膨胀应用程序大小if config.name == "Debug" &&已定义?(target.product_type) &&target.product_type == "com.apple.product-type.framework"config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = "YES"结尾结尾结尾结尾

I'm willing to add unit and UI tests to my app.

I first configured unit tests with success, I tried to do the same with UI tests. Here is my Podfile, after adding a new UI Testing Bundle target :

platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!

def shared_pods
pod 'Bolts'
pod 'Branch'
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
pod 'GoogleAnalytics'
pod 'GooglePlaces'
pod 'Parse'
pod 'Toast-Swift'
end

target 'MyTarget' do
shared_pods
end

target 'MyTargetUITests' do
shared_pods
end

target 'MyTargetUnitTests' do
shared_pods
end

However, when I try to run the automatically created MyProjectUITests test case, which only contains the basic setup and without even a @testable import MyProject:

import XCTest

class MyProjectUITests: XCTestCase {

    override func setUp() {
        continueAfterFailure = false
        XCUIApplication().launch()
    }
}

I'm getting this error:

Running tests... The bundle "MyProjectUITests" couldn’t be loaded because it is damaged or missing necessary resources. Try reinstalling the bundle.

(dlopen_preflight(/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/MyProjectUITests): Library not loaded: @rpath/libswiftSwiftOnoneSupport.dylib

Referenced from: /private/var/containers/Bundle/Application/5A1FE39F-E675-4A47-9BF4-FBCDB96F5821/MyProjectUITests-Runner.app/PlugIns/MyProjectUITests.xctest/Frameworks/Toast_Swift.framework/Toast_Swift

Reason: image not found)

What is wrong? Thanks for your help.

EDIT : for information, it works fine when I remove that Toast_swift pod from my UI test target and let it only in my app and unit test targets.

解决方案

Check out this issue on the cocoapods github issue tracker.

I'm still a little confused as to why this became a problem but the setting the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES to YES using this script fixed the issue for me.

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            # This works around a unit test issue introduced in Xcode 10.
            # We only apply it to the Debug configuration to avoid bloating the app size
            if config.name == "Debug" && defined?(target.product_type) && target.product_type == "com.apple.product-type.framework"
                config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = "YES"
            end
        end
    end
end 

这篇关于无法加载包“MyProjectUITests",因为它已损坏或缺少必要的资源.尝试重新安装捆绑包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆