A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
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
- Create Project: Go to the Firebase Console and create a new project.
- Android: Add an Android App. Register using the package name from your
.csprojfile. Downloadgoogle-services.json. - iOS: Add an iOS App. Register using the Bundle ID. Download
GoogleService-Info.plist.
Step 2: MAUI Project Configuration
- Install Nuget Packages: Install the following in your MAUI project:
-
Plugin.Firebase(Main plugin) -
Plugin.Firebase.Analytics -
Plugin.Firebase.Crashlytics
-
- Add Configuration Files:
- Android: Move
google-services.jsontoPlatforms/Android/. Right-click the file, select Properties, and set Build Action toGoogleServicesJson. - iOS: Move
GoogleService-Info.plisttoPlatforms/iOS/.
- Android: Move
- Configure Android:
- Open
Platforms/Android/AndroidManifest.xmland ensure internet permissions are enabled. - Update
Platforms/Android/Resources/values/strings.xmlto include Firebase config values if needed, althoughGoogleServicesJsonoften 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