Quantcast
Channel: Active questions tagged react-native+android - Stack Overflow
Viewing all articles
Browse latest Browse all 29603

Why is firebaseApp already initialized in React Native on Android?

$
0
0

When I try to run this code on android, I get the error FirebaseApp name [DEFAULT] already exists! In this thread, it says that firebaseApp is initialized on app startup, but then why can you call initializeApp like in this thread? It seems like my code is functionally similar to the code in the second thread, so why am I getting an error? It works fine on iOS, so I'm completely lost. What have I missed?

Edit: Forgot to mention that all of the testConfig values are stored in an .env file that is accessed by the react-native-config library.

Edit 2: Changing firebase.initializeApp(testConfig); to firebase.initializeApp(testConfig, 'fire'); fixes android, but breaks ios, causing error No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()

Code:

import firebase from '@react-native-firebase/app';import '@react-native-firebase/auth';        // for authenticationimport '@react-native-firebase/storage';     // for storageimport '@react-native-firebase/firestore';   // for cloud firestoreimport '@react-native-firebase/functions';   // for cloud functionsimport '@react-native-firebase/messaging';   // for cloud messagingimport Config from 'react-native-config'const testConfig = {  apiKey: Config.REACT_APP_FIREBASE_TEST_API_KEY,  authDomain: Config.REACT_APP_FIREBASE_TEST_AUTH_DOMAIN,  databaseURL: Config.REACT_APP_FIREBASE_TEST_DATABASE_URL,  projectId: Config.REACT_APP_FIREBASE_TEST_PROJECT_ID,  storageBucket: Config.REACT_APP_FIREBASE_TEST_STORAGE_BUCKET,  messagingSenderId: Config.REACT_APP_FIREBASE_TEST_MESSAGING_SENDER_ID,  appId: Config.REACT_APP_FIREBASE_TEST_APP_ID,  measurementId: Config.REACT_APP_FIREBASE_TEST_MEASUREMENT_ID};const fire = firebase.initializeApp(testConfig);

Logcat:

2020-04-16 11:05:17.269 25458-25543/com.nativeminutetech E/unknown:ReactNative: Exception in native call    java.lang.IllegalStateException: FirebaseApp name [DEFAULT] already exists!        at com.google.android.gms.common.internal.Preconditions.checkState(Unknown Source:29)        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@19.3.0:295)        at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@19.3.0:268)        at io.invertase.firebase.common.RCTConvertFirebase.readableMapToFirebaseApp(RCTConvertFirebase.java:97)        at io.invertase.firebase.app.ReactNativeFirebaseAppModule.initializeApp(ReactNativeFirebaseAppModule.java:55)        at java.lang.reflect.Method.invoke(Native Method)        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)        at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)        at android.os.Handler.handleCallback(Handler.java:790)        at android.os.Handler.dispatchMessage(Handler.java:99)        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)        at android.os.Looper.loop(Looper.java:164)        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)        at java.lang.Thread.run(Thread.java:764)

Viewing all articles
Browse latest Browse all 29603

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>