Xamarin, Firebase: ” Default FirebaseApp is not initialized in this process” – though initializeApp() is called?

Issue

Im starting to go crazy over that line:

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

I have no clue what is causing that. I AM calling FirebaseApp.IntApp(this) and my package name is matching … Why is it not working?

protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);
}



protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    SetContentView (Resource.Layout.Main);

    firebase  new FirebaseClient("2131099704");
    Firebase.FirebaseApp.InitializeApp(this);

    FirebaseDatabase.Instance.GetReference("chats").AddValueEventListener(this);

    fab  FindViewById<Button>(Resource.Id.fab);
    edtChat  FindViewById<EditText>(Resource.Id.input);
    lstChat  FindViewById<ListView>(Resource.Id.list_of_messages);


    fab.Click + delegate
    {

        PostMessage();
    };



    if (FirebaseAuth.Instance.CurrentUser  null)
        StartActivityForResult(new Android.Content.Intent(this, typeof(SignIn)), MyResultCode);
    else
    {
        Toast.MakeText(this, "Welcome " + FirebaseAuth.Instance.CurrentUser.Email, ToastLength.Short).Show();
        DisplayChatMessage();
    }
}

private async void PostMessage()
{
    var items  await firebase.Child("chats").PostAsync(new MessageContent(FirebaseAuth.Instance.CurrentUser.Email, edtChat.Text));
    edtChat.Text  "";
}

public void OnCancelled(DatabaseError error)
{

}

public void OnDataChange(DataSnapshot snapshot)
{
    DisplayChatMessage();
}

private async void DisplayChatMessage()
{
    lstMessage.Clear();
    var items  await firebase.Child("chats")
        .OnceAsync<MessageContent>();

    foreach (var item in items)
        lstMessage.Add(item.Object);
    ListViewAdapter adapter  new ListViewAdapter(this, lstMessage);
    lstChat.Adapter  adapter;
    }
}

}

Solution

Try to initialize firebase within your Application class (OnCreate method). But first download the google-services.json file from the project console, and make sure it has the “GoogleServicesJson” value as Build Action.

Answered By – alberto basoli

Leave a Comment