Xcode 10.1: Pods not compiling when running UITest - ios

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.

Related

Swift app downloaded from source control doesn't run on my machine, runs on coworkers

The bounty expires in 3 days. Answers to this question are eligible for a +50 reputation bounty.
Oscar A Garcia wants to draw more attention to this question.
A coworker and I are taking over an iOS app hosted on GitLab. This app utilizes cocoapods, and the Pods directory is included in the repo. My understanding is we should be able to pull the repo and run it on Xcode without issues.
My coworker is able to download the app from source control and run it on his machine. Mine is getting errors such as "Cannot find type 'AnimationView' in scope". He is running an M1 MacBook, I'm running an intel-based MacBook air. I'm opening the workspace file that was generated by CocoaPods, not xcodepro.
Here's a list of things I've tried:
Regenerating the pods via the command line by running pod reintegrate, then pod update, opening Xcode and cleaning the build folder, and then running again.
Changing the minimum iOS deployment target on Xcode to the highest deployment target of the pods in my podfile.
Changing the architectures on the app build settings to i386 and x86_64 rather than the default.
Clicking "Update to recommended settings" when Pods throws a warning.
None of these seem to work, I'm at a loss at this point. Since it runs on my coworker's machine I'm assuming there must be something wrong with how my app is detecting the libraries or how it's compiling.
Here's my podfile:
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'
target 'projectname' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for projectname
pod 'Purchases'
pod 'Firebase/Analytics'
pod 'Firebase/Core'
pod 'Firebase/Storage'
pod 'Firebase/Database'
pod 'Firebase/Firestore'
pod 'Firebase/Auth'
pod 'SwiftyJSON'
pod 'CleanyModal'
pod 'MagicTimer'
pod 'lottie-ios'
pod 'FBSDKCoreKit'
end
I suspect the problem is not related to pods.
The reason for this is if you start a fresh iOS Xcode project, called emptyproj, and then close the iOS project in Xcode, you can then go to that project directory and place in a Podfile into that directory with your above contents but with the name projectname replaced with emptyproj, you can then do
pod install
and then once it has created emptyproj.xcworksapce open it in Xcode.
You will notice that there is no symbol called AnimationView. There is only LottieAnimationView.
So the missing symbol must be in the actual app on GitLab, not the pod dependencies.
What I suggest is to look at any build phases in the build of the project to see if any scripts that are architecture-specific get run.
Another debugging strategy is to get your co-worker onto your machine and do the setup herself on your machine, which might succeed (an unmentioned step) or fail (stronger evidence that it is a machine or architecture related matter).
This looks like you have different version of lootie , ask your coworker to check version he is currently using
for this you can use command:
pod outdated
When you run pod outdated, CocoaPods will list all pods that have newer versions that the ones listed in the Podfile.lock
then
use pod with specyfic version like this:
pod 'lottie-ios', '3.5.0'
instead of:
pod 'lottie-ios'
If you didn't add version when you run 'pod install' you will get newest available version.
and AnimationView is part of lottie liblary.
After adding version number run 'pod install'.
In such a case you can ask for the Podfile.lock of your co-worker and can check for the already installed specific version of the relevant pod, and if there any mismatch with there installed version with yours, update your pod file by adding that version and then pod install. and also if you guys don't need to work with latest version of the pods it is always better to use pod with versions.

Pods with multiple targets getting error?

Alright, Ive seen this problem in a lot of places but I cant find a clear solution - they all seem to be pretty convoluted. I am trying to add pods to a Message Extension. I get this error when doing the following and running pod install - this happens as soon as opening and trying to run the workspace:
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'LaunchPack' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for LaunchPack
pod 'lottie-ios'
end
target 'MessagesExtension' do
# Comment this line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for MessagesExtension
pod 'lottie-ios'
end
Here I pod to both targets and per solutions like https://www.bountysource.com/issues/35748866-missing-embed-pods-build-phase-for-messages-extension-target I have manually added the library (Lottie) to the Link Binaries with Libraries section of BOTH targets:
The link above describes "The issue can be fixed by ensuring that the framework is weakly linked and manually adding a "Run Script" build phase for the -frameworks.sh script"
however I don't understand what they mean by that. Where I can I link the framework other than where I have already?
How can I add pods to my MessageExtension?
I have faced the same issue when adding pods for multiple targets what I did was uninstalled and deleted all the pods file first. Then create multiple targets and after that add the pod file and installed it and works fine for me.

Cocoapods testing linker error

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.

IOS Run custom shell script 'embed pods framework' file not found error

I am getting an error when building my app after i removed reference to a framework i added incorrectly. i am new to ios and cocoapods
/Users/MyMac/Library/Developer/Xcode/DerivedData/MyApp-ewxrexwuczochyctnqvlyusrtvvy/Build/Intermediates/MyApp.build/Debug-iphonesimulator/MyApp.build/Script-5874133373474758EEC76CFD.sh: line 2: /Users/MyMac/Documents/MyApp/Pods/Target Support Files/Pods-MyApp/Pods-MyApp-frameworks.sh: No such file or directory
I am aware that the file and directory don't exist and that is the way it should be but where is it finding the reference to this file so i can remove it and be rid of the error.
I have checked the following:
Linked Frameworks andLibraries under the general tab of my project
The frameworks group in the project
framework search paths under build settings tab
i have also run pod update after removing it from the pod file
How can i fix this?
Edit
back story
I was trying to add the framework https://github.com/Alliants/ALAccordion . in the instruction it said to use
# Podfile
target 'My Target' do
use_frameworks!
pod "ALAccordion"
end
so i added MyApp where my Target is and it created a framework named Pods-MyApp which i cant remove completely.
hope this helps
Cocoapods wrote a tool to completely deintegrate all of this stuff from your project so it goes back to running standalone. It sounds like you had an issue adding the correct target, so use this:
https://github.com/CocoaPods/cocoapods-deintegrate
Then try again so you can at least start from good ground. Hope this helps!
It happened with a prerelease version of Cocoapods 1.2.0.beta.1, by reverting to stable version and running pod install, then clean build, it worked.
why
use_frameworks!
after
target ... do
here is example
platform :ios, '8.0'
use_frameworks!
inhibit_all_warnings!
target 'XXX' do
pod 'RealmSwift'
end
target 'XXXTests' do
pod 'RealmSwift'
end

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