Build error with pods only for test target - ios

What I did :
Tried to build project
What happened :
It failed with "Error:The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation."
The libPods.a is not generated
I have the latest cocoapods installed, and this is my podfile :
source 'https://github.com/CocoaPods/Specs.git'
inhibit_all_warnings!
platform :ios, '7.0'
target :MyProjectTests, :exclusive => true do
pod 'OCMock'
end
I have seen similar issues reported at CocaPods project on github, but nothing seems to work.
I don't need any pods for my main project, I'd just like to use OCMock for testing.

You should check that the Manifest.lock file is identical to Podfile.lock.
These files should be the same when a pod install command is executed.
If not, you should check if someone that is collaborating on your GIT project is changing the Podfile.lock (as it is usually under version control).

Yo have to add the Test target to the Podfile between the main target:
target :mainTarget do
link_with "MainTarget"
//Added pods...
target :tests do
link_with "Tests"
end
end

Related

How to fix duplication error of GoogleUtilities Swift?

I am using firebase for tracking crashes in my project and i am using the below pods in my project.
pod 'FirebaseCore', '6.6.4'
pod 'FirebaseMessaging', '4.3.0'
pod 'FirebaseAnalytics','6.3.1'
While archieving this project for placing the testflight build, i am getting duplication error below for google utilities :
Multiple commands produce '/Path/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/GoogleUtilities.framework':
1) Target 'GoogleUtilities-00567490' has create directory command with output '/Path//IntermediateBuildFilesPath/UninstalledProducts/iphoneos/GoogleUtilities.framework'
2) Target 'GoogleUtilities-54e75ca4' has create directory command with output '/Path//IntermediateBuildFilesPath/UninstalledProducts/iphoneos/GoogleUtilities.framework'
When I checked my Pods settings in my build setting, I saw google utilities added twice in project. I have removed the one of the GoogleUtilities it's getting an error.
Note: I can able to run the build and I can't able to archive it. Is there any fix for achieving this build, without changing the legacy build system?
Because I have enabled the library distribution for my SDK, so when I made changes into legacy its throws an error.
Adding pod 'GoogleUtilities', '~> 7.7.0' to all the targets that use Firebase pods will make it work. In my case, this included 3 targets: iOS app, iMessage Extension and UnitTests.
No need to add this part explicitly:
def google_utilites
pod 'GoogleUtilities/AppDelegateSwizzler'
pod 'GoogleUtilities/Environment'
pod 'GoogleUtilities/Logger'
pod 'GoogleUtilities/MethodSwizzler'
pod 'GoogleUtilities/NSData+zlib'
pod 'GoogleUtilities/Network'
pod 'GoogleUtilities/Reachability'
pod 'GoogleUtilities/UserDefaults'
end
Update the Podfile to explicitly request all the needed GoogleUtilties subspecs. Examine the Podfile.lock to find the list.
There is a lot more detail at this CocoaPods issue.
This issue occurred to me when i added a new target to my project using very similar but not equal firebase dependencies, so GoogleUtilities was duplicated because my other target doesn't need as much dependencies from utilities as the main one so, basically (with the help of Paul Beusterien answer) went to the Pods project and look at both targets (GoogleUtilities-xxx) -> Build Phases -> Compile Sources and look at the differences in files added, basically in the new target was missing 'GoogleUtilities/UserDefaults' and 'GoogleUtilities/MethodSwizzler' but this can be different in any case, so i just did a compilation like this
platform :ios, '13.0'
def google_utilites
pod 'GoogleUtilities/AppDelegateSwizzler'
pod 'GoogleUtilities/Environment'
pod 'GoogleUtilities/Logger'
pod 'GoogleUtilities/MethodSwizzler'
pod 'GoogleUtilities/NSData+zlib'
pod 'GoogleUtilities/Network'
pod 'GoogleUtilities/Reachability'
pod 'GoogleUtilities/UserDefaults'
end
abstract_target 'AggregatedPodsTarget' do
use_frameworks!
google_utilites
pod 'FirebaseCore'
pod 'FirebaseAuth'
pod 'FirebaseFirestore'
pod 'FirebaseStorage'
pod 'FirebaseFunctions'
pod 'FirebaseAnalytics'
pod 'FirebaseMessaging'
pod 'Firebase/Crashlytics'
pod 'Google-Mobile-Ads-SDK'
target 'MainApp' do
end
target 'MainApp Dev' do
end
end
abstract_target 'ExtensionPodsTarget' do
use_frameworks!
google_utilites
pod 'FirebaseAuth'
pod 'FirebaseFunctions'
target 'Extension' do
end
target 'Extension Dev' do
end
end
after this i just did pod install and i went back to have only one GoogleUtilities Dependency
This worked for me, it's similar to this Bogdan's answer
Summarising steps
Add pod 'GoogleUtilities' so they don't clash from different targets
Clean install your pods (pod deintegrate and pod install)
Might need pod repo update.
Reopen xcode and archive, you would see single GoogleUtilities now
I saw this error when I tried archiving one of my projects where I had recently introduced another new target.
Going into the pod settings for this new target, I noticed that the iOS deployment version was different (14.4) from the iOS deployment version in the main Runner target (12.0) - something I had missed when I was initially configuring this new extension target.
The only difference between the iOS deployment versions I saw was that 14.4 had App Extensions enabled. Since that was something inconsequential to my project, I was happy matching the iOS deployment
versions for both my targets so they could refer to only one set of dependencies. After that, I just removed the duplicate pods for the version that I had removed. And I could archive again.
For each of your Targets, got to Build Settings -> check the iOS Deployment Target -> change the version so that they match.
For most circumstances, there is no reason why they should be different. But if for some reason you deem they should be different, checkout Paul Beusterien's answer and follow that.
We had the similar issue on Flutter project using firebase_core and firebase_analytics dependencies. Adding pod 'GoogleUtilities', '~> 7.7.0' in all the targets in the Podfile under ios folder.
target 'Runner' do
use_frameworks!
use_modular_headers!
pod 'GoogleUtilities', '7.7.0'
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
target 'customnotificationext' do
use_frameworks!
pod 'GoogleUtilities', '7.7.0'
end

Pods not installing properly

I had been installing pods and the pods get installed properly . However , in the Project navigator , the .xcconfig files are red in color and I cannot set the same in the project-> info -> configurations either as they don't get listed and only none is listed. When debugged , I could find that the .xcconfig files were getting accessed by the xcode in the following path
/Volumes/Macintosh HD/Users/xxxxxxxxxx/Documents/xxxxxxxx/app/Pods/Pods/Target Support Files/Pods-broadcastuploadSetupUI/Pods-broadcastuploadSetupUI.release.xcconfig
/Pods is there twice , Because of which I am getting the following errors :
diff: /Podfile.lock: No such file or directory
diff: /Manifest.lock: No such file or directory
error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
I am working with Xcode 9 beta . Can anyone kindly help ?
P.S , I have tried sudo gem install , pod update , disintegrate , install and everything that is available on the internet as a solution. I'd be glad if anyone could help
This is my podfile :
#platform :ios, ‘11.0’
source 'https://URL_TO_ACCESS_PODSPEC_FOR_POD'
source 'https://github.com/CocoaPods/Specs.git'
target 'app' do
pod 'objective-zip', '~> 1.0'
pod 'AssistScreenShareKit'
use_frameworks!
end
target ‘broadcastupload’ do
pod 'AssistScreenShareKit'
use_frameworks!
end
target ‘broadcastuploadSetupUI' do
pod 'AssistScreenShareKit'
use_frameworks!
end
Error :
The file “Pods-app.release.xcconfig” couldn’t be opened because there is no such file. (/Volumes/Macintosh HD/Users/xxxxxxxx/Documents/xxxxx/app/Pods/Pods/Target Support Files/Pods-app/Pods-app.release.xcconfig)
Steps to install pod
Open a terminal window, and $ cd into your project directory.
To create a Podfile you need to to run $ pod init.
Open your Podfile. The first line should specify the platform and
version supported.
platform :ios, '9.0'
use_frameworks! target 'yourProjectName' do
pod 'Alamofire' end
Then install the pod
pod install
First delete all pods and Podfile.lock
open terminal and go to folder path
Edit your podfile by this
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
//add your all pods
end
pod install
close xcode and open MyApp.xcworkspace file
check for more: Command-line Reference
This will help you.
update your Cocoapods version, I had this problem with Cocoapods 1.5.3 and it was fixed in 1.6.1
to do that open terminal and just type
gem install cocoapods

Xcode Unit Testing with Cocoapods

I've been banging my head against a wall with this for the last few days but despite multiple Google/SO/Github searches I can't find a resolution to the issues I'm having!
All I'm trying to do is create some unit tests for my app which makes use of Firebase pods.
I'm using Xcode 7.3.1 & Cocoapods 1.0.1. Update: Issue remains with Xcode 8.0
With this podfile:
platform :ios, '9.0'
use_frameworks!
inhibit_all_warnings!
target 'MyApp' do
pod 'Firebase'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
target 'MyAppTests' do
inherit! :search_paths
end
end
In my XCTest class I get
Missing required module 'Firebase'
error at #testable import MyApp
Alternatively with this podfile:
platform :ios, '9.0'
use_frameworks!
inhibit_all_warnings!
def common_pods
pod 'SwiftyTimer'
pod 'Firebase'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
end
target 'MyApp' do
common_pods
end
target 'MyAppTests' do
common_pods
end
The tests build but my console is littered with warnings e.g.:
Class <-FirebaseClassName-> is implemented in both ...MyApp... and
...MyAppTests... One of the two will be used. Which one is undefined
I had the same issue. I solved it by moving pod 'Firebase' to my test target. Change your Podfile to this:
platform :ios, '9.0'
use_frameworks!
inhibit_all_warnings!
target 'MyApp' do
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
target 'MyAppTests' do
inherit! :search_paths
pod 'Firebase'
end
end
Try changing the inheritance to :complete, as in:
target 'MyAppTests' do
inherit! :complete
end
Importantly it allows anyone else checking out your repo to just do a pod update as usual without having to copy .xcconfig files or other hackery just to build.
Select your Unit Test Target setting.
Go to Build Settings.
Look for Header Search Paths.
Add this value $(SRCROOT)/Pods with recursive, then Xcode will resolve the path for you.
Here is Example
The issue is that Firebase does something special with the Header Search Paths after CocoaPods generates its own value for the setting so CocoaPods doesn't pick up on this change in order to carry it over to the test target. You can solve this one of two ways:
Locate MyAppTests.<configuration>.xcconfig in the file navigator and add the following to HEADER_SEARCH_PATHS:
${PODS_ROOT}/Firebase/Analytics/Sources [*]
Find the setting for Header Search Paths in Build Settings and add that same value as in option 1 to the list. You shouldn't need to set it as recursive.
* As per AKM's comment, this changed to ${PODS_ROOT}/Firebase/Core/Sources in version 3.14.0
Adding ${SRCROOT}/Pods/Firebase/CoreOnly/Sources into the unit test target's "Header search paths" fixed the problem.
Steps:
Select your unit tests target
Go to Build Settings
Search for header search path
Add ${SRCROOT}/Pods/Firebase/CoreOnly/Sources
After this the tests can run and the error will disappear.
Three Steps before I could get this to work:
CocoaPods : 1.5.0
Swift 4
Firebase : 4.13.0
Step 1:
Make sure to add the following target block into your podfile.
# Uncomment the next line to define a global platform for your project
platform :ios, '11.3'
target 'TIMII' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for TIMII
pod 'Firebase/Core'
pod 'Firebase/Database'
pod 'Firebase/Auth'
pod 'Firebase/Storage'
target 'TIMIITests' do
inherit! :search_paths
pod 'Firebase/Core'
end
end
Step 2:
Within the YourAppTests Project Navigator Build Settings tab. Find the Header Search Path row and add to Debug the following line
$(inherited) ${PODS_ROOT}/Firebase/Core/Sources
Step 3:
In terminal run:
pod update
A simpler method that also works:
target 'MyApp' do
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
target :MyAppTests
end
The problem is recorded in the firebase project here:
https://github.com/firebase/firebase-ios-sdk/issues/58
There is a workaround:
Add "${PODS_ROOT}/Firebase/Core/Sources" to your Tests target only
under Build Settings -> Header Search Paths
but this is also fixed by upgrading to CocoaPods 1.4.0 or later, which is a better solution.
At the time I'm writing this (November 2017) cocoapods 1.4.0 is still in beta, so to install it you need to explicitly request the beta:
gem install cocoapods --pre
This and then doing a pod install solved the problem running my tests.
I tried all the above and ran into various different errors, originally starting with Missing required module 'Firebase', then getting "Class ... is implemented in both ... " or linker issues if I tried to add Firebase Pods to my test target.
The solution that worked for me was to:
Remove test target entirely from Podfile and run 'pod update' to ensure the XCode project is in sync.
Open my test target's Build Settings and update header search paths to only include the following 3 items:
$(inherited) non-recursive
$(SRCROOT)/Pods/Headers/Public recursive
$(SRCROOT)/Pods/Firebase recursive
At this point cleaning the build folder, re-building then re-running the tests worked for me. Hope this helps someone!
The solution for me was to update cocoapods to version 1.1.0.rc.2.
sudo gem install cocoapods --pre
I had a similar problem. Phrased in terms of your question, I copied the contents of my MyApp.<configuration>.xcconfig file to my MyAppTests.<configuration>.xcconfig file. I cleaned and built the tests, and it worked.
Add "${PODS_ROOT}/Firebase/Core/Sources" to your Tests target only under
Build Settings -> Header Search Paths
As #Will mentioned an issue around Header Search Paths after CocoaPods installation.
I have a project with multiple targets where pod 'Firebase' embedded into separate module, lets say MyProject-Shared. Firebase pod at 'Podfile' installed only for 'MyProject-Shared' target. Other modules, which wants to use 'MyProject-Shared' can't be compiled due an error:
'missing required module "Firebase" '
The trick in my case was to add following missing header search path at each target's Build Settings referencing to Analytics-Framework:
"${PODS_ROOT}/Firebase/CoreOnly/Sources"
Please see pic below:
Hope it will save your time.
Missing required module Firebase NO CocoaPods solution
For those who encounter the same problem but NOT using CocoaPods:
If you're using Firebase, than you have some folder containing Firebase.h and module.modulemap file. For example - YOUR_PROJECT_DIR/Linking
If your Main project target is working correct way, than you should go to ProjectSettings -> Targets. Select test target. Search for User headers and add the path to YOUR_PROJECT_DIR/Linking. Select recursive option and you should be good to go.
See the screenshot for more details:

Build fails after updating cocoapods to 1.0.1

I updated cocoapods today, deleted the Pods folder entirely and executed pod install.
When i am trying to build now, i receive the error in the attached image.
My podfile looks the following:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/artsy/Specs.git'
platform :ios, '9.0'
inhibit_all_warnings!
use_frameworks!
target 'MyTarget' do
pod '....'
end
I tried adding #define LOG_OBJC_MAYBE(...) to my pch file but it did not help. What might be the issue?

How to add one pod to multiple targets in Cocoapods?

Right now I need to add LiveSDK to multiple targets. Please see below:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
target :CalDoKit do
pod 'LiveSDK'
end
pod 'Google-API-Client/Calendar'
pod 'LiveSDK'
As you can see the LiveSDK pod added twice. And I am getting warning from the console output when I run the application: One of the two will be used. Which one is undefined.
What's the correct way to add one pod to multiple targets?
New code:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
link_with 'CalDo', 'CalDoKit'
pod 'LiveSDK'
target :CalDo do
pod 'SVProgressHUD'
end
But I am getting warning:
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `TestKit` to `Pods/Target Support Files/Pods/Pods.debug.xcconfig` or include the `Pods/Target Support Files/Pods/Pods.debug.xcconfig` in your build configuration.
Solution 1:
Remove that 'target :xx do ... end' and add pod without defining targets. It will add the pod for all targets.
Solution 2:
Delete that podfile and run pod init command from terminal. this will make a new podfile with all the targets used in the project and then you can add pods separately for each target
Add this to the Podfile
target :AnotherTarget do
pod 'LiveSDK'
end
EDIT
This is the final Podfile source
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '7.0'
target :CalDoKit do
pod 'LiveSDK'
end
target :OtherTarget do
pod 'LiveSDK'
end
If you execute pod init console command on your project folder, it will create the Podfile with built in code.
See here: http://guides.cocoapods.org/syntax/podfile.html#target

Resources