Cocoapods testing linker error - ios

Whenever I build my testing target (the standard target that Xcode generates), the build fails with an cryptic error:
framework not found Pods_AppName_AppNameTests
which I take to mean the pod generated target for my tests can't be found.
My podfile is pretty simple:
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.
EDIT:
It is NOT the format of my podfile. This is the default setup given to me by running pod init. There may very well be a bug in cocoapods but the format is correct.
EDIT 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
That particular error is from Travis but I get the same one in Xcode locally.

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, pod install, then remove it, and pod install again, from the test target, like this:
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. 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. That leads me to believe that there's some hidden bug in the Cocoapods test setup which I'll have to investigate more.
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.

Related

Xcode 10.1: Pods not compiling when running UITest

I am trying to implement UITests in an application I'm working on.
When I am in my UITests.swift file and I try to run the app from a test, Xcode gives the following error for some of the pods I'm using:
Command CompileSwift failed with a nonzero exit code
It gives this error for a bunch of pods that are compiling just fine when running the regular project:
My PodFile looks as follows:
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
source 'https://github.com/cocoapods/specs.git'
project 'Project.xcodeproj'
use_frameworks!
# Define all thirdparty pods we need
def thirdparty
pod 'Moya', '~> 11.0'
pod 'Alamofire'
pod 'SwiftyJSON'
pod 'Differ'
.. a bunch of other pods
end
# Pods for Project project
target 'Project' do
thirdparty
end
# Pods for ProjectTests
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end
I'm having a hard time reasoning why this is happening, as my project normally compiles just fine. Other posts on S.O. regarding this problem report that the problem also occurs when building the project rather than just running for a test
Question How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
How can I make sure that all pods I use in my project, also compile correctly when building from a UITest?
The only way to know whether something will build or not is to try to build it. So when you change your CocoaPods configuration, even if that's just to update to a newer version of one or more pods, you need to try building each target.
target 'ProjectUITests' do
thirdparty
pod 'Nimble'
end`
According to your Podfile, you've got the pod Nimble being used only in the ProjectUITests target. If that's the only target that fills to build, then it seems likely that that pod is the culprit.
Except for one case (at least as far as you've shown) your Podfile doesn't specify versions for the various pods that it specifies. If you leave out the version for a given pod, your project will use the latest available version. That means that anytime you update your pods you'll pull down the latest version, even if that new version contains breaking changes. It would be safer to specify the version that you know works, or at least to limit the version to minor version and patch updates, like:
pod 'Nimble', '~>7.0'
That will let CocoaPods automatically use the latest version up to but not including 8.0. If the pod developer properly follows the semantic versioning scheme, that should ensure that you don't inadvertently pull in any breaking changes.
The problem is that target :AppModuleTests do do not have an app host and you are using inherit! :search_paths. This means that this target would find the dependencies to load them from the host but in this case there is none.
target TestApp do
pods
target :AppModuleTests
end
This worked for me.

Why would boilerplate unit tests in a boilerplate Cocoa Touch Framework project with a single Cocoapod dependency fail without even running?

Here are the step needed to reproduce:
(1) Using XCode 9.2, create a new Cocoa Touch Framework project called "Whatever" including Unit Tests.
(2) Close project and add the following podfile to the project folder.
platform :ios, '10.0'
use_frameworks!
target 'Whatever' do
pod 'Signals'
# Signals is used, but any pod seems to produce the problem
end
(3) Run pod setup and pod install.
(4) Open Whatever.xcworkspace.
(5) Open the Test Navigator and run the boilerplate tests.
Not only do the tests fail, but the little diamonds in the line numbers fail to turn red, or any colour
What is happening here, please?
Thank you for reading.
I suspect this question is a duplicate, but you likely need to add your test target to your Podfile. In this example, I assume it is WhateverTests.
platform :ios, '10.0'
use_frameworks!
target 'Whatever' do
pod 'Signals'
# Signals is used, but any pod seems to produce the problem
end
target 'WhateverTests' do
inherit! :search_paths
pod 'Signals'
end
After making this change, run pod install.

Cocoapods project settings issues

I seem to have a issue with my project settings, in Xcode 8. The issue is as follows:
When adding a new Pod - lets say, Pod Firebase - the install works, and adds the necessary files to my project. I can then, do #Import Firebase
All is fine, up to this point. However, as soon as I make a reference to the Firebase API example: [FirApp configure]; - all is still fine - autocomplete on Xcode works as expected and no issues. However, when building I then get a compile time issue which states:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_FIRAppIndexing", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The only way I am able to solve this - is by manually adding the _FIRAppIndexing.framework in my projects, Build settings, under Link Libraries with Libraries
To do that, I just drag and drop the frame work from the project navigator to the correct section under link libraries.
This works sometimes; as with other parts of the Firebase SDK, I get runtime crashes.
So, to try get to the root cause, I created a brand new test project, installed the Pods using Pod install - I however did not have to add the framework manually to Libraries - its actually not even listed there.
Everything in the test project worked just fine, at compile and run time.
Which leads me to believe its something in my project settings that's causing this.
Things I have tried
Removed cocoapods completely with pod deintegrate and removed all
other traces of it. Then did a clean build. Then Pod install
Added -objc to linker flag
Podfile
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'MyApp' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
use_frameworks!
# Pods for MyApp
pod 'Crashlytics'
pod 'AsyncDisplayKit', '>= 2.0'
pod 'Firebase'
pod 'Firebase/Messaging'
pod 'FBSDKCoreKit'
pod "HockeySDK", :subspecs => ['AllFeaturesLib']
pod 'Fabric'
pod 'FirebaseAppIndexing'
pod 'AFNetworking', '~> 3.0'
pod '1PasswordExtension', '~> 1.8.4'
target 'MyAppTests' do
inherit! :search_paths
# Pods for testing
end
end
GitHub example project
https://github.com/TanderZA/MyApp
I duplicated my current project - and removed all files. Problem still exists. You will see the project won't compile due to linker errors, with references to the Firebase AP.
By manually adding the frameworks to Link Libraries with Libraries, you will see that it should compile. But that is not how it should work. The current project has an issue with infoPlist.strings that I did not solve. But the project is in the state to demonstrate the issue.
I have checked the project, it seems you have messed up with schemes.
Create a new scheme properly then install the pods again and as the project is in Obj-C you don't need to enable frameworks in the podfile.
So comment like # use_frameworks!
Also update the pods using pod update
Then select the new scheme and build the project in it.
Let me know if you are not able to do it.
It is a xcode bug by the way
But try this :
Upgrade to latest version of xcode and Pods
Remove all architectures in your project
Clean your project
Add arcitectures from start.
This should resolve the issue.
Have you tried to use frameworks?
# platform :ios, '10.0'
use_frameworks!
target 'MyApp' do
I am not sure though but I think what you need is pod 'Firebase/Core'. not pod 'Firebase'.
This link have the list of the Firebase framework that can be used.
And, in the video on the top of the page it says something about there is no single pod that can be installed and you need to set each one of them on the podfile depending on the features you want.
My guess they mislead us in some places where they had pod 'Firebase'. I dont think that they meant that it should do the work.
som try the following:
# Pods for MyApp
pod 'Firebase/Core'
pod 'Firebase/Messaging'
.
.
I know that you said that you had it work on another new project.

Updating project to CocoaPods 1.0.0 resulting in many errors

I am working on updating some of my libraries to work with CocoaPods 1.0.0.
I have updated my Podfile to use the new DSL syntax and ran pod update which seemed to work as expected.
Problem 1:
I now have a bunch of errors I have never seen before in my project mainly
Ambiguous use of internal linkage declaration XXX defined in multiple modules
Does anyone know what this error means and how to fix it?
Problem 2:
#import <CocoaPodName/Header.h> style imports can no longer find the appropriate header file.
Problem 3:
FBSnapshotTestCase will no longer build and gives the error Use of private header outside of module scope...
All of these problems began as soon as I ran pod update after updating to CocoaPods 1.0.0.
Podfile:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'App' do
...
target 'Tests' do
inherit! :search_paths
pod 'FBSnapshotTestCase'
end
end
Update:
I was able to get everything to compile by removing use_frameworks! from the Podfile and using pod 'FBSnapshotTestCase/Core.
Ideally I would prefer to be able to use use_frameworks!, but it seems there may be a bug in CocoaPods 1.0.0?

Cocoapods missing pod include files when removing all test pods

I have an iOS project I've been working on for some time, successfully, in which I used several pods for my main target, and then a couple more for my test target. Everything went swimmingly.
I was using a pod for tests, Expecta, because I needed to test asynchronous code. Now that Apple has added support for asynchronous testing in the latest Xcode, I rewrote my tests to use that, and want to remove Expecta from my project.
After doing that, my tests no longer compile, with errors about the header files from the pods no longer being found. For instance, `'FacebookSDK/FacebookSDK.h' file not found' error compiling one of my tests.
I've tried deleting all the Cocoapod-generated stuff and redoing it from pod install with no luck.
Versions: Cocoapods 0.35.0, Xcode 6.1.1, OS X 10.10.1.
My new, no-test-pods Podfile is:
# Uncomment this line to define a global platform for your project
platform :ios, '7.0'
target 'Meow' do
pod 'AFNetworking', '2.4.1'
pod 'TestFlightSDK', '3.0.2'
pod 'AWSiOSSDKv2/S3', '2.0.11'
pod 'Facebook-iOS-SDK', '3.20.0'
pod 'TTTAttributedLabel', '1.10.1'
pod 'DTCoreText', '1.6.14'
pod 'ReactiveCocoa', '2.3.1'
end
target 'MeowTests' do
end
Removing the MeowTests target hasn't helped either.
While I was typing the above :) I found this question; which says to add a link_with line to my podfile, and change the configuration file setup in the Info pane of my Project.
However, because I was removing the last pod from my test target, I also needed to delete the CocoaPods-specific phases from my test target. In the Build Phases tab, I removed Check Pods Manifest.lock and Copy Pods Resources.
Now my tests run fine. (And I can start rewriting them in Swift :) )

Resources