在你的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