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

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.

Related

Is there a way to add Flutter to an extension Target on iOS xCode?

Assuming I have a basic flutter app and I add a target in xcode for the ios app. Would there be any way to link it to the main Flutter folder so I can do an "import Flutter" in the extension the same way it's done in the AppDelegate then start a FlutterEngine, MethodChannel etc locally in the extension ?
I partially succeded adding a module compiled as an "ios-framework" (otherwise with cocoapods there's a dependency conflict error) to the extension xcode target, yet this means including a redundant Flutter dependency and although it runs, I'm not sure at this point this is very stable... For this reason I'm wondering if there's a way to make an import of the main Flutter directly ?
Thanks

Cannot import FirebaseMessaging in Service Extension target

I have a SwiftUI project where I added the Firebase dependency using the "Add Package" at the project level.
I could then put 'import FirebaseMessaging' inside a swift file and it would build without error, so I know the dependency is added correctly.
I then added a UNNotificationServiceExtension by going to File > New > Target and adding a Notification Service Extension.
Now in code in my new target in the same project, 'import FirebaseMessaging' will not resolve.
If I right click on the service extension and select 'Add Package', it will not allow me to add the firebase sdk package to the service extension, as it is already added to the project.
How can I get the Firebase dependency to be added to my service extension target?
I think I figured out a solution! Although the package has been added to the project, it needs to be explicitly added to the Service Extension as well.
Once it's been added, you should be able to import FirebaseMessaging from the Service Extension.

Unknown type name 'SCNetworkReachabilityRef'

Getting this error while building and running the project.
Unknown type name '**SCNetworkReachabilityRef**'
Unknown type name '**SCNetworkReachabilityFlags**'
I am using Xcode 9.2 with Swift 4.0
I have installed following pods into my Project which uses Cocoapod 1.6.0.
GoogleMaps
CardIO
QuickBlox
QMServices
QMChatViewController
Quickblox-WebRTC
TTTAttributedLabel
SDWebImage
SVProgressHUD
SearchEmojiOnString
IAlertView+Blocks
Alamofire
SwiftyJSON
Fabric
Crashlytics
QMServices
QuCore-ThirdParty
SAMKeychain
FunkyObjC (version 1.3)
Firebase/Core
List item
I try to troubleshoot the error! But didn't get the proper solution!
Can anyone please help me with this issue?
This is a way to figure out yourself
Select SCNetworkReachabilityFlags.
Press ⌘C to copy the string.
Press ⇧⌘0 (zero not o) to open the documentation.
Press ⌘V to paste SCNetworkReachabilityFlags into the search field.
You will see
On the right side there is the enclosing framework. SCNetworkReachabilityFlags belongs to SystemConfiguration
You have to #import a framework to be able to access its types.
So add
#import SystemConfiguration
in the file where the Reachability API is used.
You need to import SystemConfiguration.
Correspondingly Class names have been changed. You would get it as suggestion in Xcode.

Integrate Flutter into CocoaTouch SDK?

I was able to follow the instructions on https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps to add Flutter as a dependency to a simple single view app and display a FlutterViewController, but did not have success trying the same process for a cocoa touch framework that depends on Flutter.
Is this currently possible? My hope was to be able to build a standalone iOS SDK that is powered by Flutter that other iOS apps could depend on with no direct dependency on Flutter.
Specifically when I tried the SDK approach, Flutter imports failed to resolve with errors relating to not being able to find the Flutter module imports:
[Xcode build error][1]][1]
error: no such module 'FlutterPluginRegistrant'
import FlutterPluginRegistrant
error: no such module 'Flutter'
import Flutter
Update:
These are the error logs I was seeing initially, but was able to get around them by vendoring the FlutterPluginRegistrant.framework and Flutter.framework with Cocoapods. With that my main app compiles fine when linked to my FlutterSDK framework that includes the flutter dependencies. The issue I'm running into now is with setting up FlutterViewController and it's FlutterEngine / FlutterDartProject to point to the correct paths within the framework for the flutterAssets / dartMain / packages urls. I'm not sure how to pull these in from the framework.
If you want to build a Framework that is essentially _just_ a Flutter module, where other iOS apps can use it without having to install/depend on Flutter SDK themselves, then yes, this can be done via one of the flutter/add-to-app options for iOS:
Option B - Embed frameworks in Xcode
also refer to the github/flutter/ios_using_prebuilt_module sample
On the other hand, if you are talking about integrating Flutter into an existing Framework, Flutter + Cocoa Touch, then no, this is currently not supported, but is being explored:
https://github.com/flutter/flutter/issues/39027
note that this would be termed “add-to-library” as opposed to "add-to-app"
also mentioned, flutter/add-to-app:
Packing a Flutter library into another sharable library or packing multiple Flutter libraries into an application isn’t supported.

Analytics not recognized

Been following the Firebase setup guide. The setup process worked, but my project doesn't recognize the Analytics type:
Analytics.logEvent // use of unresolved identifier 'Analytics'
Xcode autocomplete shows AnalyticsConfiguration, but nothing else. As a sanity check, here's what I did to set up my project:
Use cocoapods to fetch Firebase/Core
Ensure I'm using the .xcworkspace file
Added the GoogleService-Info.plist for my project
In my app delegate, import Firebase and call FirebaseApp.configure()
Realized what the problem was. My project name was "Analytics", and it somehow influenced the visibility of the framework named "Analytics".

Resources