由于以下错误,我无法运行测试用例:
- 无法加载捆绑包“ UITests”,因为它已损坏或缺少必要的资源。尝试重新安装捆绑软件。
- 库未加载:@ rpath / Alamofire.framework / Alamofire。
- 原因:找不到图片
从两天后开始尝试搜索和解决,但无法解决此问题,请有人帮忙。
Answers:
我能够通过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!
,请参见此链接:
# 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
inherit! :search_paths
从target 'MyAppUITests'
。还是需要保留它?
inherit! :search_paths
但没有成功,但除了这些提及之外,我还拥有其他CocoaPods lib。我以前没有任何想法。
这是因为您的广告连播仅适用于框架目标,而没有适用于测试目标。将测试目标添加到您的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
)才能修复错误。
就我而言,我需要用分隔UI测试目标use_frameworks!
。
如果您use_frameworks!
在Podfile顶部的全局位置进行了全局指定,则将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
解决我的问题的步骤如下:1)从pod文件中删除UITests目标。最初,我在pod文件中包含以下内容:
target 'XUITests' do
inherit! :search_paths
end
2)拆解豆荚(与豆荚解整合)
3)安装吊舱(使用吊舱安装)
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时。解决方案:Targer的iOS版本错误,我换成了经过测试的Target的相同版本,一切正常!!