简体   繁体   中英

No Firebase App '[Default] has been created - call firebase.initializeApp()

My app is connected to firebase and auth is working fine. However, when trying to use firestore I can't figure out this problem.

Possible Unhandled Promise Rejection (id: 0): Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()

I am getting the above error however, I am already calling initializeApp and not sure what else to try. I am trying to get access to a collection on firestore and print it out but it gives me the error when I try to access firestore.

I have tried doing console.log(firebase.app().name) which gives the name of the app, so not sure how it is not initialised.

var firebaseConfig = {
  apiKey: "***",
  authDomain: "***",
  databaseURL: "***",
  projectId: "***",
  storageBucket: "***",
  messagingSenderId: "***",
  appId: "***",
  measurementId: "****",
}

firebase.initializeApp(firebaseConfig)
const db = firebase.firestore()

My imports are

import "firebase/firestore"
import firebase from "firebase"
import firestore from "@react-native-firebase/firestore"

I have tried so many different questions on here and forums but nothing has helped

Make sure that you made all the configuration correctly by following this video

And just make sure that the first 2 lines at main function are (follow the same order):

 void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  //rest of the code
  runApp(MyApp());
}

As per Kishan above. I added the google-services.json file into the android level folder and modified both build.gradle files.

https://firebase.google.com/docs/android/setup followed step 3 here to update the build.gradle files to use google-services.

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