This is my code
app gradle
Project gradle
In your application class, initialize FirebaseApp in onCreate() method and remove it from Your Activity in order to have Firebase initialize into entire application, not just to one Activity.
@Override
public void onCreate() {
super.onCreate();
FirebaseApp.initializeApp(this);
}
Also add apply plugin: 'com.google.gms.google-services' at the end of app gradle:
dependencies {
....
}
apply plugin: 'com.google.gms.google-services'
For more: Make sure to call FirebaseApp.initializeApp(Context) first in Android
Make sure that you have added google-services.json to your app after regidterin to firebase.
Refer:https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseApp