Cocoapods 测试链接器错误

Cocoapods testing linker error

每当我构建测试目标(Xcode 生成的标准目标)时,构建都会失败并出现神秘错误:

framework not found Pods_AppName_AppNameTests

我的意思是找不到为我的测试生成的 pod 目标。 我的播客文件非常简单:

use_frameworks!

target 'AppName' do

  pod 'ReactiveCocoa'
  pod 'RealmSwift'
  pod 'ObjectMapper'
  pod 'Moya'
  pod 'Moya/ReactiveCocoa'
  pod 'pop'
  pod 'Heimdallr'
  pod 'Heimdallr/ReactiveCocoa'
  pod 'Alamofire'
  pod 'AlamofireImage'
  pod 'SwiftDate'
  pod 'DropdownAlert'
  pod 'NibDesignable'


  target 'AppNameTests' do
    pod 'Quick'
    pod 'Nimble'
  end
end

我正在使用 Cocoapods 1.0.1。

编辑:

这不是我的播客文件的格式。这是 运行 pod init 给我的默认设置。 cocoapods 中很可能存在错误,但格式正确。

编辑 2:

如果我包括:

inherit! search_paths

在我的测试目标中,测试失败说:

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

没有该行,测试也无法构建,但这次出现链接器错误:

Ld /Users/travis/Library/Developer/Xcode/DerivedData/Reactify-fqgxzcgedmqljrangqdkxpwdfxne/Build/Intermediates/Reactify.build/Debug-iphonesimulator/Reactify_Tests.build/Objects-normal/i386/Reactify_Tests 正常 i386

那个特定的错误来自 Travis,但我在 Xcode 本地得到了同样的错误。

这是最奇怪的事情,我以前绝对试过这个,但我只是删除了测试目标,创建了一个新目标,你瞧,它有效。据我所知,这两个目标之间的唯一区别是一个名为 MyApp_Tests,另一个名为 MyApp_ExampleTests。如果这是原因,我会感到惊讶,但在这一点上很难说。

我要说的是,作为旁注,我所指的项目并不是我见过这种情况的唯一项目。我的最后四个项目都遇到了这个错误,都是从 Cocoapods 1.0.0 开始创建的。这让我相信 Cocoapods 测试设置中存在一些隐藏的错误,我将不得不对其进行更多调查。

此外,删除测试目标并创建一个新目标似乎只适用于这种特殊情况。在其他项目中,错误仍然存​​在。而且我可以说这不仅仅是我的本地设置,因为我的 travis 构建也会持续失败。

上周我也一直在与此作斗争——我最终发现 "solution" 可靠地工作是添加 inherit! search_paths、pod install,然后删除它,然后 pod install再次从测试目标开始,像这样:

source 'https://github.com/CocoaPods/Specs.git'

project 'CityWeather/CityWeather.xcodeproj'
install! 'cocoapods',
         :deterministic_uuids => false

use_frameworks!

platform :ios, '9.3'

abstract_target 'CityWeather_Base' do

  <... pod list here, contents don't seem to matter ...>

  target 'CityWeather' do
  end

  target 'CityWeatherTests' do
  # NB. If it starts refusing to link the test frameworks,
  # adding and then removing inherit! :search_paths here appears to help.
  #inherit! :search_paths
  end

end

这至少比每次发生在你身上时都创建一个新目标要省事,根据我上周的判断,我预计很快就会发生在你身上。很烦人。花了尽可能多的时间来尝试从发生问题的提交日志中推断出来,但这并不明显。如果我设法找到足够的时间来解决问题以打开一个有用的问题,我会在这里更新。但与此同时,希望我的 "solution" 能稍微提高您的工作效率。