简体   繁体   中英

No such module 'Firebase' - Xcode and Swift Package Manager

I'm trying to incorporate Firebase Analytics into my SwiftUI project in Xcode. I've added the Firebase package using Swift Package Manager, and am able to call FirebaseApp.configure() to initialize my app in my UIApplicationDelegate class. Now I'm trying to log analytics events and am running into an issue.

My UIApplicationDelegate class is in an iOS-specific folder. I have a service class that is in a Shared folder (to be used across both iOS and macOS builds). In my service class, I've added a line that says:

import Firebase

However, when I go to build my iOS target I get an error saying:

No such module 'Firebase'

I don't know why this import statement would cause a problem, since I have the very same statement in my UIApplicationDelegate class. The only thing I could think of was that somehow my Shared classes don't know about Firebase? Maybe? When I view the iOS target in my project it shows that the FirebaseCrashlytics and FirebaseAnalytics frameworks have been added to it.

I'm at a loss as to what's happening. All other things I've found online are for Cocoapods, which I'm not using for dependency management. I'm leveraging the Swift Package Manager for this. Any help would be greatly appreciated!!

I had the same issue but the post below from GitHub should fix it:

https://github.com/firebase/firebase-ios-sdk/issues/9014#issuecomment-979489434

After installing the Firebase swift package, make sure you add the Firebase libraries to Frameworks:

TARGETS -> Your App -> General -> Frameworks, Libraries, and Embedded Content -> hit '+' to add the Firebase libraries you want:

在此处输入图像描述

I had the same error but with 'FirebaseCore'. I tried everything, but what worked for me was to add @_implementationOnly to import. So it should look like this:

@_implementationOnly import FirebaseCore

Here is the link that helped me and it says:

You could use @_implementationOnly import for the modules from the third-party SDK if you aren't using anything from that SDK as part of your module's public interface.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM