Native Library Interop wrapper for Firebase Performance Monitoring in .NET MAUI
This project provides a cross-platform .NET MAUI wrapper for Firebase Performance Monitoring, making it easy to integrate Firebase Performance into your MAUI apps with a clean C# API. It leverages the CommunityToolkit.Maui.NativeLibraryInterop template to bridge native Android and iOS Firebase SDKs.
- Cross-platform support: Android and iOS
- Easy-to-use C# interface for starting/stopping performance traces
- Integrates seamlessly with .NET MAUI projects
- Includes a sample MAUI app demonstrating usage
Include the package in your .NET MAUI project (replace with your package ID if published):
dotnet add package Maui.FirebasePerformance
- Firebase Setup
Download your google-services.json from the Firebase Console.
Place it in Platforms/Android of your MAUI app.
Initialize Firebase in MainApplication.cs:
Firebase.FirebaseApp.InitializeApp(this);
Download your GoogleService-Info.plist from Firebase Console.
Add it to Platforms/iOS in your MAUI app.
Ensure Firebase/Performance pod is installed via CocoaPods.
using Maui.FirebasePerformance;
public partial class MainPage : ContentPage
{
private readonly IFirebasePerformance _performance;
public MainPage(IFirebasePerformance performance)
{
InitializeComponent();
_performance = performance;
// Enable performance collection
_performance.SetPerformanceCollectionEnabled(true);
// Start a performance trace
var trace = _performance.StartTrace("app_startup");
DoSomeWork();
trace.Stop();
}
private void DoSomeWork()
{
// Simulate work
Thread.Sleep(1000);
}
}
- void SetPerformanceCollectionEnabled(bool enabled) – Enable or disable performance monitoring.
- ITrace StartTrace(string traceName) – Start a performance trace.
- void Start() – Begin trace measurement.
- void Stop() – Stop the trace and send metrics to Firebase.
The Firebase.Performance.Sample project demonstrates:
- Initializing Firebase
- Starting/stopping traces
- Cross-platform usage in a MAUI app
Development
This project uses the NativeLibraryInterop template. To update or extend bindings:
- Android: Add or update Gradle dependencies in Firebase.Performance.Android.
- iOS: Update Podfile in Firebase.Performance.iOS and run pod install.
- Generate bindings:
-- Android: Use Java binding syntax in ApiDefinition.cs -- iOS: Use Objective Sharpie to generate C# bindings for .framework headers
Build the solution, then run the sample app to test functionality.
This project is licensed under the MIT License. It uses Firebase SDKs which are governed by Firebase Terms of Service.
- CommunityToolkit.Maui.NativeLibraryInterop
- Firebase Performance Monitoring
- .NET MAUI Documentation