Error: Firebase is not configured. Ensure that you have configured 'google-services.json' correctly

4.8k Views Asked by At

After running expo install expo-firebase-core expo-firebase-analytics and downloading both google-services.json and GoogleService-Info.plist from firebase console and placing them on the root of my project.

When i call Analytics.logEvent, expo go gives an error.

Possible Unhandled Promise Rejection (id: 0):
Error: Firebase is not configured. Ensure that you have configured 'google-services.json' correctly.

this is my TopLevelComponent.js:

import React from 'react'
import * as Analytics from 'expo-firebase-analytics';
import { createRootNavigator } from './router'

const RootNavigator = createRootNavigator()

const TopLevelComponent = props => {
    const { screenProps } = props;
    const { checkLogin } = screenProps;
    const getActiveRouteName = navigationState => {
        if (!navigationState) {
            return null
        }
        const route = navigationState.routes[navigationState.index]
        // Parse the nested navigators
        if (route.routes) return getActiveRouteName(route)
        return route.routeName
    }

    return (
        <RootNavigator
            onNavigationStateChange={async (prevState, currentState) => {
                const currentScreen = getActiveRouteName(currentState)
                const prevScreen = getActiveRouteName(prevState)
                if (prevScreen !== currentScreen) {
                    checkLogin()
                    Analytics.logEvent('event')
                }
            }}
            screenProps={props.screenProps}
        />
    );
}

export default TopLevelComponent

Am i missing any other config?

Is there any other way to configure firebase-analytics besides this files?

I'm using expo-44.0.6 and expo-firebase-analytics-6.0.1

3

There are 3 best solutions below

2
On BEST ANSWER

I had the same error. This is how I fixed it:

  1. Go to app.js and add

"googleServicesFile": "./GoogleService-Info.plist"

under the "iOS" section. example:

  "expo": {
    "name": "",
    "slug": "",
    "version": "",
    "orientation": "",
    "icon": "",
    "splash": {
      "image": "",
      "resizeMode": "",
      "backgroundColor": ""
    },
    "updates": {
      "fallbackToCacheTimeout":
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet":,
      "bundleIdentifier": "",
      "googleServicesFile": "./GoogleService-Info.plist"
    },
  1. Similar for Android:

    "android": {
           "googleServicesFile": "./google-services.json",
           "adaptiveIcon": {
             "foregroundImage": "",
             "backgroundColor": ""
           }
    
  2. Add this for under the "web" section:

     "web": {
           "config": {
             "firebase": {
               "apiKey": "",
               "authDomain": "",
               "projectId": "",
               "storageBucket": "",
               "messagingSenderId": "",
               "appId": "",
               "measurementId": "G-**********"
             }
           },
           "favicon": "./assets/favicon.png"
         }
    
  3. Then in the app:

     import * as Analytics from 'expo-firebase-analytics';
    

    const pageView = async (routeName, params) => { await Analytics.logEvent(routeName, params); };

0
On

I had same mistake. In my case i was using the Expo Bare Workflow with the SDK 45.

I only add these line in my android/build.gradle

 dependencies {
    classpath("com.android.tools.build:gradle:4.1.0")
    classpath 'com.google.gms:google-services:4.3.10' /* Add this line */
}

And in the android/app/build.gradle on the top file

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services' /* Add this line */

Clean the project and run: production npx react-native run-android

That´s works for me :)

0
On

I was experiencing a similar issue connecting to analytics on Firebase. I had all the configurations mentioned above for web and ios. I wanted to set up analytics for my expo app and only use the expo-firebase-analytics library. I was testing the connection from an ios simulator.

My issue was simply resolved by adding a second app to my Firebase for the ios platform. The GoogleService-Info.plist file was auto-generated in Firebase and available to download and be placed in my project.

app ios app to firebase

Initially, I only added an app to my Firebase for the web platform so I was unable to establish a connection between the ios simulator and the analytics on Firebase.