我收到错误,这是我的错误:请务必先调用FirebaseApp.initializeApp(Context)

问题描述 投票:-2回答:1

这是我的代码

enter image description here

app gradle

enter image description here

项目gradle

enter image description here

android
1个回答
0
投票

在你的application class中,用FirebaseApp方法初始化onCreate()并将其从你的Activity中删除,以便让Firebase初始化为整个应用程序,而不仅仅是一个Activity。

@Override
public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(this);
}

同时在app gradle结束时添加apply plugin:'com.google.gms.google-services':

dependencies {
    ....
}
apply plugin: 'com.google.gms.google-services'

更多信息:Make sure to call FirebaseApp.initializeApp(Context) first in Android

在注册到firebase之后,请确保已将google-services.json添加到您的应用中。请参阅:https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseApp

© www.soinside.com 2019 - 2024. All rights reserved.