A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello @Vignesh Palthurai ,
Thanks for reaching out.
You can refer to the following steps:
- On iOS, throw new Exception() is treated as a managed .NET exception. The Mono runtime catches it before Crashlytics can detect it. I recommend replacing this:
[RelayCommand]
private void TestFirebaseCrash()
{
throw new Exception("Firebase Crash Test");
}
into this:
[RelayCommand]
private void TestFirebaseCrash()
{
CrossFirebaseCrashlytics.Current.TestIt();
}
[RelayCommand]
private void TestFirebaseNonFatal()
{
try
{
throw new Exception("Firebase Crash Test");
}
catch (Exception ex)
{
CrossFirebaseCrashlytics.Current.RecordException(ex);
}
}
-
FinishedLaunchingfires too late for Crashlytics to properly set up its crash handlers. It must be initialized inWillFinishLaunchinginstead.
Additionally, calling CrossFirebase.Initialize("default") with a string parameter may cause a "Default app has already been configured" crash.
I recommend moving all Firebase initialization into MauiProgram.cs:
using Microsoft.Extensions.Logging;
using Microsoft.Maui.LifecycleEvents;
#if IOS || ANDROID
using Plugin.Firebase.Analytics;
using Plugin.Firebase.Crashlytics;
#endif
#if IOS
using Plugin.Firebase.Core.Platforms.iOS;
#elif ANDROID
using Plugin.Firebase.Core.Platforms.Android;
#endif
namespace MauiApp2;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.RegisterFirebaseServices()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
#if DEBUG
builder.Logging.AddDebug();
#endif
return builder.Build();
}
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
#if IOS || ANDROID
builder.ConfigureLifecycleEvents(events =>
{
#if IOS
events.AddiOS(iOS => iOS.WillFinishLaunching((_, _) =>
{
CrossFirebase.Initialize();
CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);
return false;
}));
#elif ANDROID
events.AddAndroid(android => android.OnCreate((activity, _) =>
{
CrossFirebase.Initialize(activity, () =>
Microsoft.Maui.ApplicationModel.Platform.CurrentActivity);
FirebaseAnalyticsImplementation.Initialize(activity);
}));
#endif
});
builder.Services.AddSingleton(_ => CrossFirebaseAnalytics.Current);
builder.Services.AddSingleton(_ => CrossFirebaseCrashlytics.Current);
#endif
return builder;
}
}
And keep AppDelegate.cs simple:
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
}
- I suggest creating an
exported_symbols.txtfile atPlatforms/iOS/exported_symbols.txt. The iOS linker hides a symbol called __mh_execute_header, which Crashlytics requires to identify the app’s entry point.
- Create the file with the following content:
__mh_execute_header
- And reference it in
.csproj:
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<MtouchExtraArgs>-exported_symbols_list $(MSBuildProjectDirectory)/Platforms/iOS/exported_symbols.txt</MtouchExtraArgs>
</PropertyGroup>
Before testing again, please rebuild and check logs:
rm -rf bin obj
dotnet build -f net10.0-ios
Please share the results or logs afterward, and I’ll be happy to help further if needed.
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.