【问题标题】:Error: Firebase is not configured. Ensure that you have configured 'google-services.json' correctly错误:未配置 Firebase。确保您已正确配置“google-services.json”
【发布时间】:2022-06-18 00:20:34
【问题描述】:

在运行 expo install expo-firebase-core expo-firebase-analytics 并从 firebase 控制台下载 google-services.jsonGoogleService-Info.plist 并将它们放在我的项目的根目录之后。

当我调用 Analytics.logEvent 时,expo go 出现错误。

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

这是我的 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

我是否缺少任何其他配置?

除了这些文件之外,还有其他方法可以配置 firebase-analytics 吗?

我正在使用expo-44.0.6expo-firebase-analytics-6.0.1

【问题讨论】:

    标签: expo expo-go


    【解决方案1】:

    我有同样的错误。 这就是我修复它的方法:

    1. 转到 app.js 并添加

    “googleServicesFile”:“./GoogleService-Info.plist”

    在“iOS”部分下。 示例:

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

      "android": {
             "googleServicesFile": "./google-services.json",
             "adaptiveIcon": {
               "foregroundImage": "",
               "backgroundColor": ""
             }
      
    2. 在“web”部分下添加这个:

       "web": {
             "config": {
               "firebase": {
                 "apiKey": "",
                 "authDomain": "",
                 "projectId": "",
                 "storageBucket": "",
                 "messagingSenderId": "",
                 "appId": "",
                 "measurementId": "G-**********"
               }
             },
             "favicon": "./assets/favicon.png"
           }
      
    3. 然后在应用中:

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

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

    【讨论】:

    • 不幸的是,问题仍然存在。这些配置我都有。
    【解决方案2】:

    我也犯了同样的错误。在我的例子中,我使用的是带有 SDK 45 的 Expo Bare Workflow。

    我只在我的 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 */
    }
    

    并且在 android/app/build.gradle 的顶层文件中

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

    清理项目并运行:production npx react-native run-android

    这对我有用:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-15
      • 2013-10-18
      • 1970-01-01
      • 2014-12-31
      • 2017-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多