【发布时间】:2017-03-21 16:49:33
【问题描述】:
由于以下错误,我无法运行我的测试用例:
- 无法加载捆绑包“UITests”,因为它已损坏或缺少必要的资源。尝试重新安装捆绑包。
- 库未加载:@rpath/Alamofire.framework/Alamofire。
- 原因:找不到图片
从两天开始尝试搜索和解决,但无法解决此问题,请有人帮忙。
【问题讨论】:
标签: ios swift travis-ci uitest
由于以下错误,我无法运行我的测试用例:
从两天开始尝试搜索和解决,但无法解决此问题,请有人帮忙。
【问题讨论】:
标签: ios swift travis-ci uitest
我能够使用 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),您需要使用其他解决方案。
【讨论】:
# 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
target 'MyAppUITests' 中删除inherit! :search_paths。还是需要保留?
inherit! :search_paths 但无法正常工作,除了这些提及之外,我还有其他 CocoaPods 库。我以前对 uitest 没有任何想法。
这是因为您的 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)才能修复错误。
在您的测试中,目标将inherit! :search_paths 更改为inherit! :complete。
请参阅documentation 了解它的作用。
【讨论】:
检查您的 UITest 目标构建设置中的部署目标是否设置为与您尝试测试的主机应用程序相同。就我而言,我稍后添加了 UITesting 目标,它使用默认部署目标 iOS 12 创建它。如果您尝试在低于 12 的 iOS 上运行 UITest,它会给我问题中提到的错误。
【讨论】:
就我而言,我需要将 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
【讨论】:
我必须将我的框架的位置添加到目标>mytestTarget>Build Settings>Runpath Search Path 下的 Runpath search Path
【讨论】:
切换到旧版构建系统修复了 Xcode 10 的问题。
【讨论】:
对于使用 Carthage 遇到此问题的任何人,我通过将 /usr/local/bin/carthage copy-frameworks 运行脚本阶段添加到 UITest 目标(而不仅仅是我的主应用程序目标)来解决它,并将框架添加为输入文件。
【讨论】:
]3
【讨论】:
解决我的问题的方法是执行以下步骤: 1) 从 pod 文件中删除 UITests 目标。 最初,我在 pod 文件中有以下内容:
target 'XUITests' do
inherit! :search_paths
end
2) 分解 pod(使用 pod deintegrate)
3) 安装 pod(使用 pod install)
4) 清理您的项目并运行该项目或您的 UITest
【讨论】:
就我而言,只需删除 inherit! :search_paths 而不更改文件结构或复制任何 pod 即可解决我的问题。
【讨论】:
我看到了答案,但没有解释所以决定发布我的。
问题是 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
【讨论】:
对我来说,错误是在构建 UITests 时。 解决方案: Target 使用了错误的 iOS 版本,我将其替换为与测试 Target 相同的版本,一切正常!!
【讨论】:
对我来说,这个问题是由于我从一个框架中引用了 UIKit 类的扩展中的一个属性,而该框架没有在引用它的文件中导入。通过不使用该属性来修复。我不确定它为什么首先编译 - 这应该是编译时错误,而不是运行时错误。
【讨论】:
就我而言,只需选择“我的 Mac”而不是“我的 Mac (Mac Catalyst)”即可运行测试。
【讨论】:
尝试将应用目标的每个 pod 复制到 UI 测试目标。 2019 年有效。
【讨论】:
如果您实际上使用的是 Cocoapods,您可能只需要运行“pod install”,构建设置就会自动更新。
【讨论】: