Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing required module 'FirebaseCore' in unit tests #10049

Open
alexanderkhitev opened this issue Jul 28, 2022 · 31 comments
Open

Missing required module 'FirebaseCore' in unit tests #10049

alexanderkhitev opened this issue Jul 28, 2022 · 31 comments

Comments

@alexanderkhitev
Copy link

alexanderkhitev commented Jul 28, 2022

[REQUIRED] Step 1: Describe your environment

  • Xcode version: 14.0 beta 4 (14A5284g)
  • Firebase SDK version: 9.3.0
  • Installation method: Swift Package Manager (select one)
  • Firebase Component: FirebaseAuth, FirebaseAnalyticsSwift, FirebaseAuthCombine
  • Target platform(s): iOS

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

I added three SDKs for now in one of my pet project and it works but when I try to launch unit tests (XCTestCase) I get error "Missing required module 'FirebaseCore'" where @testable import AppName is declared. Do we have any solutions for this? Thanks.

Relevant Code:

Screen Shot 2022-07-28 at 8 10 45 PM

@google-oss-bot
Copy link

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

@morganchen12
Copy link
Contributor

Off the top of my head, this might be due to the FirebaseCore module headers not being visible from your test target. You can check your search paths build settings to see if this is the case.

Otherwise, if you could upload a test project that repros this issue, it would help us identify the root cause.

@alexanderkhitev
Copy link
Author

hey @morganchen12 ! Yes, sure. It's a simple project. I'll also have a look on your suggestion (paths build settings).
FirebaseSDKs.zip

@paulb777
Copy link
Member

Thanks for the great repro @alexanderkhitev

Add FirebaseAuth as a linker dependency to the test targets:

Screen Shot 2022-07-29 at 10 49 21 AM

@alexanderkhitev
Copy link
Author

Thanks for the great repro @alexanderkhitev

Add FirebaseAuth as a linker dependency to the test targets:

Screen Shot 2022-07-29 at 10 49 21 AM

Thank you. I have only one question. Unless in this case we do not receive errors like this one?
Class FIRCoreDiagnosticsLog is implemented in both

@paulb777
Copy link
Member

paulb777 commented Aug 3, 2022

Good question. I see that also. It seems that Xcode is using different search path algorithms between compiling and linking, but I'm not sure why.

@paulb777 paulb777 reopened this Aug 3, 2022
@paulb777 paulb777 removed their assignment Aug 3, 2022
@morganchen12
Copy link
Contributor

Ok, I was able to work around this by adding -Xcc -fmodule-map-file="/path/to/FirebaseCore.modulemap" in the test targets' Other Swift Flags build setting. What's going on is explained via @neonichu here.

It's not immediately clear to me what the best solution for us from a library vendor standpoint is.

@morganchen12 morganchen12 changed the title Missing required module 'FirebaseCore' Missing required module 'FirebaseCore' in unit tests Aug 15, 2022
@JarnoRFB
Copy link

JarnoRFB commented Nov 18, 2022

This tripped me off as well. I first had Missing required module 'FirebaseFirestore'. After including this as described by @paulb777 I got errors about AppCheck so now I just ended up linking all possible firebase libraries to the test target, which got it working. Have to say that this issue was pretty hard to find, so maybe including some hints in the SPM README would be a good idea.

@matkuznik
Copy link

Could someone explain why we have to add Firebase* to the tests targets? I have 5 others frameworks which do not have to be added 🤔.

Thanks 😊

@nesimtunc
Copy link

nesimtunc commented Dec 21, 2022

Yes, same here with @matkuznik

Adding libs to test target is not a problem, however running tests are crashed due random errors from Firebase. For example: -[FBLPromise HTTPBody]: unrecognized selector sent to instance

My test has nothing to do with Firebase.

@morganchen12
Copy link
Contributor

@nesimtunc this is an unrelated issue. Make sure the -ObjC linker flag is present in your test target, or file a new issue with a repro if the crash persists.

@morganchen12
Copy link
Contributor

Could someone explain why we have to add Firebase* to the tests targets? I have 5 others frameworks which do not have to be added 🤔.

Thanks 😊

@matkuznik you should not add the frameworks to the test target or you'll have duplicate class definitions. See this comment for a workaround: #10049 (comment)

@nesimtunc
Copy link

I had to switch to pods, with that the error has gone. Thank you @morganchen12

@GlebCherkashyn
Copy link

GlebCherkashyn commented Dec 27, 2022

guys, I found really weird solution, here is a short story for a better context
I have xcode project with multiple targets, and I have one test bundle for each target to test snapshots.
We've added 2 more targets about 6 months ago, I did it, and I added 2 new test bundles, so it's kinda "fresh" in my memory. And now we have to add another one, but I couldn't do that due to Missing required module issue. I've tried multiple ways, like switching to pods/SPM, linking binaries for test bundle... But I've noticed one thing: Bundle Loader setting in Build settings had two slashes (see screenshot). When I manually changed value to

$(BUILT_PRODUCTS_DIR)/<MyApp>.app/<MyApp>

it worked!

This is definitely xcode 14 issue, because when you change a host for test bundle, it puts two slashes again!

I really hope that will help you, I've spent 3-4 days searching a solution

Screenshot 2022-12-27 at 17 37 37

@matkuznik
Copy link

matkuznik commented Dec 28, 2022

@nesimtunc this is an unrelated issue. Make sure the -ObjC linker flag is present in your test target, or file a new issue with a repro if the crash persists.

Should I add OTHER_LDFLAGS = "-ObjC"; to the production target as well?

EDIT:
I've just found

Analytics requires clients to add -ObjC linker option.

and

If you've installed FirebaseAnalytics, add the -ObjC option to Other Linker Flags in the Build Settings tab.

in SwiftPackageManager.md. But I have not installed FirebaseAnalytics and I have those crashes as well.

@matkuznik
Copy link

Could someone explain why we have to add Firebase* to the tests targets? I have 5 others frameworks which do not have to be added 🤔.
Thanks 😊

@matkuznik you should not add the frameworks to the test target or you'll have duplicate class definitions. See this comment for a workaround: #10049 (comment)

Thanks a lot for you suggestion. Could you help me with finding a path to the FirebaseCore.modulemap? I can not localise it. I'm using SPM.

@morganchen12
Copy link
Contributor

@matkuznik it should be in the Derived Data directory for your target.

@matkuznik
Copy link

@matkuznik it should be in the Derived Data directory for your target.

Thanks. I found a few. One is located in the Index.noindex/Build/Intermediates.noindex/GeneratedModuleMaps-iphonesimulator/FirebaseCore.modulemap and I'm using it.

There is also a env variable to this folder GENERATED_MODULEMAP_DIR so the Build settings is: -Xcc -fmodule-map-file="$GENERATED_MODULEMAP_DIR/FirebaseCore.modulemap"

@bennoland
Copy link

I found a different (better?) workaround.

Under my test target build settings, Testing, Test Host
Change it from:
"$(BUILT_PRODUCTS_DIR)/MyApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/MyApp"
to:
"$(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp"

The BUNDLE_EXECUTABLE_FOLDER_PATH variable was evaluating to empty, so I was seeing a double slash in the path "$(BUILT_PRODUCTS_DIR)/MyApp.app//MyApp"

@alexanderkhitev
Copy link
Author

BUILT_PRODUCTS_DIR)/<MyApp>.app/<MyApp>

Hey @GlebCherkashyn ! I tried your solution. It works. I tried with Xcode Version 14.2 (14C18). 🤔

@chawkinsnz-hnry
Copy link

@bennoland's suggestion worked a trick for my project using SPM and Xcode 14.2(14c18).

I also tried making a fresh empty project in Xcode with Firebase as the sole SPM dependency and hit the same problem where tests would fail to build as soon as the host app's code imported Firebase. Following @bennoland's suggestion this fixed it here too

Screenshot 2023-01-06 at 12 38 16 PM

@macintosh-HD
Copy link

@chawkinsnz-hnry This helped me a lot!
These steps should be included in the https://github.com/firebase/firebase-ios-sdk/blob/master/SwiftPackageManager.md

@zouritre
Copy link

zouritre commented Apr 6, 2023

if you are using Cocoapods adding Pods_MyAppTests.framework to your test target Link Binary With Libraries in Build Phases settings fixed it for me on a particular project. On another project instead I had to add all libraries related to Firebase in the same way.

image

@roman-sundurov
Copy link

@GlebCherkashyn @bennoland
Thank you for your attempts to help. I faced the same problem and tried your solution. It didn't help, unfortunately. If I add "@testable import TheWallet" to the test, the "missing required modules" error immediately occurs.

Screenshot 2023-04-09 at 04 55 07

Screenshot 2023-04-09 at 04 52 28

Screenshot 2023-04-09 at 04 52 47

Screenshot 2023-04-09 at 04 53 09

@snowtema
Copy link

snowtema commented May 16, 2023

I tried this workaround, problem with -[FBLPromise HTTPBody]: unrecognized selector sent to instance was fixed. But now I got new error: -[FBLPromise firebaseInstallationID]: unrecognized selector sent to instance.

UPD
Problem solved by adding all Firebase libraries to Test target.

@SebastianBoldt
Copy link

I found a different (better?) workaround.

Under my test target build settings, Testing, Test Host Change it from: "$(BUILT_PRODUCTS_DIR)/MyApp.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/MyApp" to: "$(BUILT_PRODUCTS_DIR)/MyApp.app/MyApp"

The BUNDLE_EXECUTABLE_FOLDER_PATH variable was evaluating to empty, so I was seeing a double slash in the path "$(BUILT_PRODUCTS_DIR)/MyApp.app//MyApp"

This solution also worked for me ;)
But does have anyone has an Idea why this is the solution to our Problem?

@byaruhaf
Copy link

byaruhaf commented Jul 8, 2023

UPD Problem solved by adding all Firebase libraries to Test target.

This worked for me not sure why, we need to do this.

@JarnoRFB
Copy link

I had all Firebase libraries linked to the test target under Link binary with libraries which resulted in slow test builds and 3 out of 4 test runs failing with -[FBLPromise HTTPBody]: unrecognized selector sent to instance. Removing the linked libraries and setting the test host appropriately instead seems to have fixed the issue.

@NfoDkt
Copy link

NfoDkt commented Jul 17, 2023

guys, I found really weird solution, here is a short story for a better context I have xcode project with multiple targets, and I have one test bundle for each target to test snapshots. We've added 2 more targets about 6 months ago, I did it, and I added 2 new test bundles, so it's kinda "fresh" in my memory. And now we have to add another one, but I couldn't do that due to Missing required module issue. I've tried multiple ways, like switching to pods/SPM, linking binaries for test bundle... But I've noticed one thing: Bundle Loader setting in Build settings had two slashes (see screenshot). When I manually changed value to

$(BUILT_PRODUCTS_DIR)/<MyApp>.app/<MyApp>

it worked!

This is definitely xcode 14 issue, because when you change a host for test bundle, it puts two slashes again!

I really hope that will help you, I've spent 3-4 days searching a solution

Screenshot 2022-12-27 at 17 37 37

Thank you SOOOO MUCH !

@CarlitosDroid
Copy link

I'm not sure but I created a project one week ago. Then I added FirebaseFirestore, Alamofire and Kingfisher dependencies from Swift Package Manager.

Screenshot 2023-08-29 at 22 48 39

Screenshot 2023-08-29 at 22 49 14

When I try to run unit tests. I've got this error:

Screenshot 2023-08-29 at 22 45 13

As @NfoDkt mentioned above. I can see the two double slashes.

Screenshot 2023-08-29 at 22 51 48

However, I've just created a new project with the same dependencies and now I don't have any issue:

Screenshot 2023-08-29 at 22 54 21

XCode Version

Screenshot 2023-08-29 at 22 54 48

@morganchen12
Copy link
Contributor

@CarlitosDroid you won't see the issue unless the modules are actually required in your tests I think.

I've updated the SPM readme's known issues section to sort issues by most replies, so this will be at the top. Thanks all for posting your workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests