You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Expo集成Firebase Analytics时提示‘Firebase is not configured’错误的配置排查咨询

Expo Firebase Analytics: 'Firebase is not configured' Error in Expo Go

Problem Description

I've run the command expo install expo-firebase-core expo-firebase-analytics to install dependencies, and downloaded google-services.json (for Android) and GoogleService-Info.plist (for iOS) from Firebase Console, placing them in my project root directory. However, when I call Analytics.logEvent, Expo Go throws an unhandled promise rejection error:

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

Here's my TopLevelComponent.js code:

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

I'm using Expo SDK 44.0.6 and expo-firebase-analytics 6.0.1. Did I miss any configuration steps? Are there alternative ways to set up Firebase Analytics besides using these two config files?


Answer

Let's break down the issues and solutions step by step:

  1. Expo Go doesn't support custom Firebase configuration
    Expo Go is a pre-built universal app, which means it can't load your project-specific google-services.json or GoogleService-Info.plist files. To use Firebase Analytics with your custom config, you need to either:

    • Use EAS Build to create a custom build of your app (this is the recommended approach for production)
    • Run expo prebuild to generate native project files, then build and run the app locally via Xcode/Android Studio
  2. You need to reference config files in your Expo project config
    Even if you place the config files in the root directory, Expo won't automatically detect them unless you specify their paths in app.json or app.config.js. Add these entries to your project config:

    {
      "expo": {
        "android": {
          "googleServicesFile": "./google-services.json"
        },
        "ios": {
          "googleServicesFile": "./GoogleService-Info.plist"
        }
      }
    }
    

    Double-check that the filenames and paths are exactly correct (case-sensitive on some systems).

  3. Ensure Firebase is initialized before using Analytics
    While expo-firebase-core usually handles initialization automatically, sometimes you need to explicitly initialize Firebase early in your app lifecycle. Add this to your root component (like App.js) before using Analytics:

    import * as FirebaseCore from 'expo-firebase-core';
    
    // Inside your component's useEffect or at the top level
    FirebaseCore.initializeAsync();
    

    This ensures Firebase is ready before you call Analytics.logEvent.

  4. Alternative: Configure Firebase via app config (no config files needed)
    If you prefer not to use the google-services.json/plist files, you can define your Firebase config directly in app.config.js. Get the config values from Firebase Console (under Project Settings > General > Your apps > Firebase SDK snippet > Config) and add them like this:

    export default {
      expo: {
        // ... other expo config
        "firebase": {
          "apiKey": "YOUR_API_KEY",
          "authDomain": "YOUR_AUTH_DOMAIN",
          "projectId": "YOUR_PROJECT_ID",
          "storageBucket": "YOUR_STORAGE_BUCKET",
          "messagingSenderId": "YOUR_SENDER_ID",
          "appId": "YOUR_APP_ID",
          "measurementId": "YOUR_MEASUREMENT_ID"
        }
      }
    }
    

    This works with both managed and bare workflows, and avoids needing to manage the native config files.

  5. Verify version compatibility
    You're using Expo SDK 44 with expo-firebase-analytics 6.0.1, which is the correct version match (per Expo's SDK documentation). Just make sure expo-firebase-core is also on a version compatible with SDK 44 (it should be, since you installed it via expo install which pulls the right version).

If you still run into issues after trying these steps, try clearing your Expo cache with expo r -c and restarting the development server.

内容的提问来源于stack exchange,提问作者pgramaca

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 19:27:41