0

I am Trying to create a xamarin android app that sends data to the firebase database that I have created I initialize it using but every time I try to start the app it gives me this exception

protected override void OnCreate(Bundle bundle)
{
        Firebase.FirebaseApp.InitializeApp(this);
        FirebaseDatabase database = FirebaseDatabase.Instance;
        DatabaseReference myRef = database.GetReference("app6-85d57:");
        myRef.SetValue("hello world"); 
        base.OnCreate(bundle);
}

Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process App6.App6. Make sure to call FirebaseApp.initilizeApp(Context) first.

how can i solve this? i can't find a solution anywhere.

1 Answers1

0
  1. Create a project in Firebase Console
  2. Create an Android app and download the google-services.json. Please make sure that the package name is the same as the package name use in your app. enter image description here
  3. Add google-services.json to root of Android project and set the Build Action to "GoogleServicesJson". You might need to close solution and reopen it again for this build action to appear. enter image description here
  4. Initialise FirebaseApp: Firebase.FirebaseApp.InitializeApp(this);

  5. In my case, the first time also will have Not initialise error. After I clean solution and rebuild again, the error is gone. Then, FirebaseApp is able to initialise normally.

Note: My Android Support Library is v25.4.0.2, Xamarin.Firebase.Database is v42.1021.1

lowleetak
  • 1,362
  • 1
  • 10
  • 19