简体   繁体   中英

How do I fix Cannot find 'FirebaseApp' in scope?

I am having a issue. Please Help. Whenever I try to run this code it has an error and says Cannot find 'FirebaseApp' in scope. Please Help!!!

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions:
      [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    FirebaseApp.configure()
    return true
  }

It sometimes happens with cocoapods. Try following steps

  1. Clean your build - Command + K

  2. Delete Derived data -> Command +. -> Locations -> Derived data -> Delete all the sub folders. Command +. -> Locations -> Derived data -> Delete all the sub folders.

  3. Now quit your Xcode and reopen it.

在此处输入图像描述 :

This solution works for me

I have imported before import Firebase but after update the pods. Additionally I have to import one more import FirebaseAnalytics

So if you need both import Firebase & import FirebaseAnalytics then keep both otherwise for Events only require import FirebaseAnalytics

It seems quite a bit depends on the broader picture of your setup. What versions are you using for:

  • Xcode?
  • Swift?
  • CocoaPods?
  • Firebase?
  • Xcode Project Format?
  • maybe others?

I ran into this same issue earlier this week, and my setup was the following:

  • Xcode 13.3
  • Swift 5
  • CocoaPods 1.11.3
  • Firebase/Analytics (8.12.1)
  • Firebase/Core (8.12.1)
  • Firebase/Crashlytics (8.12.1)
  • FirebasePerformance (8.12.0)
  • Xcode Project Format 3.2-compatible

When I went to build (for sim or device, didn't matter) I was getting Cannot find 'FirebaseApp' in scope as an error. I literally did what Google says to do: https://firebase.google.com/docs/database/ios/start#set_up

import Firebase

...put the above in AppDelegate.swift and run FirebaseApp.configure() in this method

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool

Didn't work.

As an experiment, I tried having FirebasePerformace , FirebaseAnalytics , and FirebaseCrashlytics code all over my app, but didn't run Firebase.configure() in the app delegate.

It compiled and ran.... but crashed when the app encountered some metrics capturing code from one of the above Firebase modules, So, clearly , the pod install worked and is fine... So it wasn't a CocoaPods issue for me.

It then seemed to me that something was awry with what was being import ed. The import Firebase statement alone (as they claim) wasn't doing what it was supposed to do.

So, what did I try? Well, having used Firebase in the past, at one point, Google recommended using import FirebaseCore . So that's what I did.

import FirebaseCore

I put the above line of code in my AppDelegate.swift file in addition to import Firebase , and problem solved. It now builds and runs on sim and device.

I would also recommend looking into what @AshvinA and @SomeshKarthik did if you are using features for those specific modules under the Firebase paradigm.

Again, your solution maybe different depending on the version(s) of various aspects of your project setup.

I cannot comment on the post for some reason, but I think I know the answer. You need to download cocoapods and install the pods for Firebase. Take a look at this link and you will see what I mean: https://firebase.google.com/docs/ios/setup

Feel free to leave a comment if you need clarification.

Edit: looked at the page, it forgot to include the command "sudo gem install cocoapods" if you don't have cocoapods installed already. Also, if you are on a Mac that is not up to Big Sur, you need to manually update ruby. Just try to find RVM (ruby version manager). I had to do it 3 times already, but I forget how to do it (its a repressed memory).

opening "xcworkspace" file in xcode instead of "xcodeproj" solved my issue.

Import these two framework in appDelegate and it should work.

import Firebase

import FirebaseFirestore

go to the firebase.h file and check this line #import <FirebaseCore/FirebaseCore.h>

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