Search code examples
expoexpo-go

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


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


Solution

  • 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); };