简体   繁体   English

Cocoapods测试链接器错误

[英]Cocoapods testing linker error

Whenever I build my testing target (the standard target that Xcode generates), the build fails with an cryptic error: 每当我构建我的测试目标(Xcode生成的标准目标)时,构建就会失败并出现一个神秘的错误:

framework not found Pods_AppName_AppNameTests

which I take to mean the pod generated target for my tests can't be found. 我认为这意味着我的测试的pod生成目标无法找到。 My podfile is pretty simple: 我的podfile非常简单:

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

I'm using Cocoapods 1.0.1. 我正在使用Cocoapods 1.0.1。

EDIT: 编辑:

It is NOT the format of my podfile. 它不是我的podfile的格式。 This is the default setup given to me by running pod init. 这是通过运行pod init给我的默认设置。 There may very well be a bug in cocoapods but the format is correct. cocoapods中可能存在一个错误,但格式是正确的。

EDIT 2: 编辑2:

If I include: 如果我包括:

inherit! search_paths

in my test target, the tests fail saying: 在我的测试目标中,测试失败说:

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

Without that line, the tests also fail to build but this time with a linker error: 如果没有该行,测试也无法构建,但这次出现了链接器错误:

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

That particular error is from Travis but I get the same one in Xcode locally. 特殊错误来自Travis,但我在Xcode中获得了同样的错误。

I've been battling with this the last week as well -- the "solution" I eventually found to work reliably was to add inherit! search_paths 我上周也一直在与此斗争 - 我最终发现可靠工作的“解决方案”是添加inherit! search_paths inherit! search_paths , pod install, then remove it, and pod install again, from the test target, like this: inherit! search_paths ,pod install,然后从测试目标中再次删除它和pod安装,如下所示:

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

That's less hassle at least than creating a new target every time it happens to you, which judging by my last week I predict to happen to you shortly. 这至少比每次碰巧你创造一个新目标更麻烦,从我上周的预测来看,我预计很快会发生在你身上。 Very annoying. 很烦人。 Spent as much time as I could spare to try to deduce from the commit logs where the problem occurs, but it's not straightforwardly obvious. 花费尽可能多的时间来尝试从发生问题的提交日志中推断,但这并不是直截了当的。 I'll update here if I manage to find the time to figure out the problem enough to open a useful issue. 如果我能找到时间找出足够的问题来打开一个有用的问题,我会在这里更新。 But in the meantime, hopefully my "solution" will improve your productivity somewhat. 但与此同时,希望我的“解决方案”能够在一定程度上提高您的生产力。

It's the strangest thing and I absolutely tried this before, but I just deleted the test target, created a new one, and lo and behold, it works. 这是最奇怪的事情,我之前绝对尝试过这个,但我刚刚删除了测试目标,创建了一个新目标,并且它看起来很有效。 The sole difference, as far I can tell, between the two targets is one was called MyApp_Tests and the other MyApp_ExampleTests . 据我所知,两个目标之间的唯一区别是一个名为MyApp_Tests ,另一个MyApp_ExampleTests I'd be surprised if that was the cause but at this point it's hard to tell. 如果这是原因我会感到惊讶,但在这一点上很难说。

I will say though as a side note, the project I was referring to is not the only project I've seen this happen with. 我会说作为旁注,我所指的项目并不是我见过的唯一一个项目。 The last four of my projects have encountered this error, all created since Cocoapods 1.0.0. 我的最后四个项目遇到了这个错误,都是自Cocoapods 1.0.0以来创建的。 That leads me to believe that there's some hidden bug in the Cocoapods test setup which I'll have to investigate more. 这让我相信Cocoapods测试设置中存在一些隐藏的错误,我将不得不进行更多调查。

Additionally, deleting the test target and making a new one only seemed to work in this particular case. 此外,删除测试目标并创建一个新目标似乎只适用于这种特殊情况。 In other projects, the error persists. 在其他项目中,错误仍然存​​在。 And I can tell it's more than just my local setup because my travis builds would also fail consistently. 我可以告诉它不仅仅是我的本地设置,因为我的travis构建也会一直失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM