140

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

doovers
  • 8,545
  • 10
  • 42
  • 70

14 Answers14

96

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
Mackarous
  • 1,467
  • 1
  • 11
  • 8
  • 1
    Thanks but I just tried that and I still have the "Class ... is implemented in both ... " issue. – doovers Jul 07 '16 at 22:44
  • 1
    It worked for me but it still doesn't make sense to me. It's not the 1st time I can tell Firebase are setting up their podspecs weirdly, cf. https://twitter.com/dirtyhenry/status/836240557311684608 but the Firebase team doesn't reply :( – Mick F Mar 03 '17 at 15:50
  • 5
    Making this change didn't immediately clear the warning, but it was resolved after I ran `pod install`. – blwinters Sep 06 '17 at 21:52
  • 1
    Half problem solved. and other half is solved by Add "${PODS_ROOT}/Firebase/Core/Sources" to your Tests target only under Build Settings -> Header Search Paths – ArgaPK Dec 28 '17 at 10:14
  • After you make this change do not forget to run `pod install` in order to update project dependencies ;) – jawad Jan 13 '20 at 13:37
  • @Mackarous how do we achieve similar functionality with 'Swift Package Manager' – Saif Sep 27 '22 at 06:44
63

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.

Andy Chou
  • 854
  • 6
  • 5
61
  1. Select your Unit Test Target setting.
  2. Go to Build Settings.
  3. Look for Header Search Paths.
  4. Add this value $(SRCROOT)/Pods with recursive, then Xcode will resolve the path for you.

Here is Example

Kanika Sharma
  • 631
  • 5
  • 11
35

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:

  1. Locate MyAppTests.<configuration>.xcconfig in the file navigator and add the following to HEADER_SEARCH_PATHS:

    ${PODS_ROOT}/Firebase/Analytics/Sources [*]

  2. 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

Lope
  • 5,388
  • 4
  • 30
  • 40
Will
  • 3,770
  • 3
  • 21
  • 19
10

Adding ${SRCROOT}/Pods/Firebase/CoreOnly/Sources into the unit test target's "Header search paths" fixed the problem. Steps:

  1. Select your unit tests target
  2. Go to Build Settings
  3. Search for header search path
  4. Add ${SRCROOT}/Pods/Firebase/CoreOnly/Sources

enter image description here

After this the tests can run and the error will disappear.

User123335511231
  • 11,654
  • 4
  • 18
  • 22
9

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

Sid
  • 963
  • 1
  • 12
  • 17
  • Prefer `pod install` over `pod update` unless you explicitly want to update your pods. Docs: https://guides.cocoapods.org/using/pod-install-vs-update.html – Sam Aug 11 '22 at 02:29
  • This answer really helped me. Thanks. Other ways from this post did not work for me. – DJ-Glock Jul 16 '23 at 18:57
8

A simpler method that also works:

target 'MyApp' do
    pod 'Firebase/Auth'
    pod 'Firebase/Database'
    pod 'Firebase/Storage'

    target :MyAppTests
end
Daniel
  • 475
  • 6
  • 10
7

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.

JosephH
  • 37,173
  • 19
  • 130
  • 154
5

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:

  1. Remove test target entirely from Podfile and run 'pod update' to ensure the XCode project is in sync.
  2. 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!

4

The solution for me was to update cocoapods to version 1.1.0.rc.2.

sudo gem install cocoapods --pre

doovers
  • 8,545
  • 10
  • 42
  • 70
2

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.

Jason
  • 413
  • 5
  • 11
  • This was the only solution that worked for me. Thanks! I'm thinking about do a post install processing in the Podfile doing this – SauloT Oct 27 '16 at 22:26
1

Add "${PODS_ROOT}/Firebase/Core/Sources" to your Tests target only under Build Settings -> Header Search Paths

Karthick Vadivel
  • 421
  • 5
  • 10
1

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: Header Search Path

Hope it will save your time.

Stanislau Baranouski
  • 1,425
  • 1
  • 18
  • 22
0

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:

enter image description here

fewlinesofcode
  • 3,007
  • 1
  • 13
  • 30