Firebase Crashlytics is not logging error in Maui .net 8.0 ?

Debasis Patra 0 Reputation points
2024-08-28T12:32:19.2466667+00:00

MainPage.xaml.cs

================

private void OnCounterClicked(object sender, EventArgs e)

{


_firebaseCrashlyticsService.Log(new Exception ("test"));

try

{

    count++;

    if (count == 1)

        CounterBtn.Text = $"Clicked {count} time";

    else

        CounterBtn.Text = $"Clicked {count} times";

    SemanticScreenReader.Announce(CounterBtn.Text);

    throw new Exception("Testing Error");

}

catch (Exception ex)

{

    _firebaseCrashlyticsService.Log(ex);

}
}

===============

MauiProgram.cs

================

    private static MauiAppBuilder RegisterFirebase(this MauiAppBuilder builder)

    {

        builder.ConfigureLifecycleEvents(events =>

        {
#if ANDROID

            events.AddAndroid(android => android.OnCreate((activity, bundle) => {

                Firebase.FirebaseApp.InitializeApp(activity);

            }));
#endif

        });

        return builder;

    }

===============================

IFirebaseCrashlyticsService.cs

===============================


#if ANDROID

using Firebase;

using Firebase.Crashlytics;

#endif

namespace PocForVersion;

public interface IFirebaseCrashlyticsService

{

void Log(Exception ex);
}

public class FirebaseCrashlyticsService : IFirebaseCrashlyticsService

{


public void Log(Exception ex)

{
#if ANDROID


        var crashlytics = FirebaseCrashlytics.Instance;

        if (crashlytics != null)

        {

            crashlytics.RecordException(Java.Lang.Throwable.FromException(ex));

        }

        else

        {

            // Handle the case where Crashlytics is not initialized

            Console.WriteLine("FirebaseCrashlytics is not initialized.");

        }
#endif


}
}

========================

google-services.json

=======================

{

  "project_info": {


  },

  "client": [

{

  "client_info": {


  },

  "oauth_client": [],

  "api_key": [

    {



    }

  ],

  "services": {

    "appinvite_service": {

      "other_platform_oauth_client": []

    }

  }

}
],

  "configuration_version": "1"

}	

================

MainActivity.cs

==================

using Firebase;

using Firebase.Crashlytics;

 protected override void OnCreate(Bundle savedInstanceState)

 {

 base.OnCreate(savedInstanceState);

 // Initialize Firebase


 

 FirebaseApp.InitializeApp(this);

 var firebase = FirebaseCrashlytics.Instance;
}
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,593 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.