Share via

Firebase implementation in MAUI mobile application

Yeswanth Srikanth 0 Reputation points
2026-04-09T14:10:06.41+00:00

Hi, I need to implement firebase analytics and Crashlytics in my MAUI mobile application using .NET 10 and I am currently doing POC in that so can you please help me with giving steps to implement firebase and log user in firebase console and Crash report as well.

Developer technologies | .NET | .NET MAUI
0 comments No comments

2 answers

Sort by: Most helpful
  1. Nancy Vo (WICLOUD CORPORATION) 2,655 Reputation points Microsoft External Staff Moderator
    2026-04-10T06:48:28.76+00:00

    Hi @Yeswanth Srikanth ,

    Thank you for your inquiry.

    I have implemented firebase analytics and crashlytics in my MAUI app and I want to share how I do, you can refer to these following steps:

    Step 1: Create your Firebase project

    1. Go to https://console.firebase.google.com
    2. Click Add project → give it a name → continue → enable Google Analytics → finish.
    3. In the project overview, click the Android icon → register your app:
    • Package name = exactly the same as your MAUI app’s Package in the AndroidManifest (usually something like com.yourcompany.yourapp).
    • Download the google-services.json file.
    1. Click the iOS icon → register your app:
      • Bundle ID = exactly the same as your MAUI app’s Bundle Identifier.
      • Download the GoogleService-Info.plist file.

    Step 2: Add the config files to your MAUI project In your MAUI solution:

    • Put google-services.json in the root (or Platforms/Android folder).
    • Put GoogleService-Info.plist in the root (or Platforms/iOS folder).

    Now edit your .csproj file (right-click project → Edit Project File) and add this inside the <Project> tag:

    <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">
    <GoogleServicesJson Include="google-services.json" />
    </ItemGroup>
    
    <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
        <BundleResource Include="GoogleService-Info.plist" />
    </ItemGroup>
    

    Right-click each file in Solution Explorer:

    • google-services.json → Build Action = GoogleServicesJson
    • GoogleService-Info.plist → Build Action = Bundle Resource.

    Step 3: Add strings.xml file by going to exact folder in your project: Platforms/Android/Resources/values/ (folder ios is similar)

    Inside that folder, create a new file called strings.xml (if it does not exists).

    Then, put this content inside strings.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <string name="com.google.firebase.crashlytics.mapping_file_id">none</string>
        <string name="com.crashlytics.android.build_id">1.0</string>
    </resources>
    
    • Right-click the strings.xml file in Solution Explorer.
    • Choose Properties.
    • Set Build Action to AndroidResource.
    • Clean + Rebuild + Run Clean the solution → Rebuild → Run on Android device/emulator.

    Step 4: Install the NuGet packages In your MAUI project, install these three packages:

    • Plugin.Firebase
    • Plugin.Firebase.Analytics
    • Plugin.Firebase.Crashlytics

    You can do it in the NuGet Package Manager or with these commands in the Package Manager Console:

    Install-Package Plugin.Firebase
    Install-Package Plugin.Firebase.Analytics
    Install-Package Plugin.Firebase.Crashlytics
    

    Step 5: Initialize Firebase in code

    You can refer to following example code:

    using Microsoft.Maui.LifecycleEvents;
    using Plugin.Firebase;
    using Plugin.Firebase.Analytics;
    using Plugin.Firebase.Crashlytics;
    
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder.UseMauiApp<App>()
               .ConfigureFonts(fonts => { ... }); // your existing code
    
        builder.ConfigureLifecycleEvents(events =>
        {
    #if ANDROID
            events.AddAndroid(android => android.OnCreate((activity, _) =>
            {
                CrossFirebase.Initialize(activity, () => Platform.CurrentActivity);
            }));
    #elif IOS
            events.AddiOS(iOS => iOS.WillFinishLaunching((_, __) =>
            {
                CrossFirebase.Initialize(new CrossFirebaseSettings());
                return false;
            }));
    #endif
        });
    
        CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);
    
        return builder.Build();
    }
    

    Step 6: Log analytics events

    Anywhere in your code (for example in a button click):

    using Plugin.Firebase.Analytics;
    
    CrossFirebaseAnalytics.Current.LogEvent("button_clicked", new Dictionary<string, object>
    {
        { "button_name", "Login" },
        { "user_id", "12345" }
    });
    

    You’ll see it live in Firebase Console → Analytics → Events

    Step 7: Test Crashlytics (force a crash)

    Please add a test button somewhere:

    private void TestCrash(object sender, EventArgs e)
    {
        throw new Exception("This is my test crash for POC!");
    }
    

    Run the app without the debugger attached (important on iOS):

    • Android: just run → crash → restart app → wait 30 seconds → check Firebase Console → Crashlytics.
    • iOS: same, but make sure you’re not debugging.

    Crashes appear in Firebase Console → Crashlytics.

    I hope this addresses your concern. If the response was useful, please consider providing feedback by following the guidance.

    0 comments No comments

  2. Marcin Policht 85,990 Reputation points MVP Volunteer Moderator
    2026-04-09T14:20:50.6966667+00:00

    This involves using the Plugin.Firebase library (e.g., v4.0.0+). Create a Firebase project, add Android (google-services.json) and iOS (GoogleService-Info.plist) configuration files to the respective Platforms folders, set build actions, and initialize the plugin in MauiProgram.cs for both platforms.

    Step 1: Firebase Console Setup

    1. Create Project: Go to the Firebase Console and create a new project.
    2. Android: Add an Android App. Register using the package name from your .csproj file. Download google-services.json.
    3. iOS: Add an iOS App. Register using the Bundle ID. Download GoogleService-Info.plist.

    Step 2: MAUI Project Configuration

    1. Install Nuget Packages: Install the following in your MAUI project:
      • Plugin.Firebase (Main plugin)
      • Plugin.Firebase.Analytics
      • Plugin.Firebase.Crashlytics
    2. Add Configuration Files:
      • Android: Move google-services.json to Platforms/Android/. Right-click the file, select Properties, and set Build Action to GoogleServicesJson.
      • iOS: Move GoogleService-Info.plist to Platforms/iOS/.
    3. Configure Android:
    • Open Platforms/Android/AndroidManifest.xml and ensure internet permissions are enabled.
    • Update Platforms/Android/Resources/values/strings.xml to include Firebase config values if needed, although GoogleServicesJson often handles this.

    Step 3: Initialize Firebase (MauiProgram.cs)

    Initialize the plugin in your MauiProgram.cs to enable services .

    using Plugin.Firebase.Auth;
    using Plugin.Firebase.Shared;
    
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .RegisterFirebase(); 
    

    Step 4: Log User and Crash Report

    Log User (Analytics): Use this to identify users in the console.

    using Plugin.Firebase.Analytics;
    
    CrossFirebaseAnalytics.Current.SetUserId("user_id_12345");
    CrossFirebaseAnalytics.Current.SetUserProperty("user_type", "tester");
    

    Log Custom Event (Analytics):

    CrossFirebaseAnalytics.Current.LogEvent("button_clicked", "button_name", "test_button");
    

    Log Exception (Crashlytics): To test, force a crash.

    using Plugin.Firebase.Crashlytics;
    
    try {
        throw new Exception("Test Crash for POC");
    } catch (Exception ex) {
        CrossFirebaseCrashlytics.Current.RecordException(ex);
    }
    

    Ensure CrossFirebase.Initialize() is called inside the OnCreate (Android) or FinishedLaunching (iOS) lifecycle, or Crashlytics will not start. In Visual Studio, you need to set the build action to GoogleServicesJson for google-services.json. It will likely take a few minutes for analytics/crashes to appear in the Firebase console.

    For details on setting up the required configuration files, refer to the official Firebase Android setup guide


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

Your answer

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