Hi Nancy Vo (WICLOUD CORPORATION),
I am facing an issue with Firebase Crashlytics on my .NET MAUI iOS application.
Previously, based on your suggestion, I added the following configuration in my .csproj to include the correct GoogleService-Info.plist based on the configuration:
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-ios' and ('$(Configuration)' == 'MDU' or '$(Configuration)' == 'UATMDU')">
<BundleResource Include="Platforms\iOS\MDU\GoogleService-Info.plist">
<Link>GoogleService-Info.plist</Link>
</BundleResource>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0-ios' and ('$(Configuration)' == 'DDU' or '$(Configuration)' == 'UATDDU')">
<BundleResource Include="Platforms\iOS\DDU\GoogleService-Info.plist">
<Link>GoogleService-Info.plist</Link>
</BundleResource>
</ItemGroup>
In MauiProgram.cs, I am initializing Firebase like this:
private static MauiAppBuilder RegisterFirebaseServices(this MauiAppBuilder builder)
{
#if IOS || ANDROID
builder.ConfigureLifecycleEvents(events =>
{
#if IOS
events.AddiOS(iOS => iOS.WillFinishLaunching((_, _) =>
{
try
{
CrossFirebase.Initialize(CreateCrossFirebaseSettings());
CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);
CrossFirebaseCrashlytics.Current.SendUnsentReports();
Runtime.MarshalManagedException += (_, args) =>
{
args.ExceptionMode = MarshalManagedExceptionMode.UnwindNativeCode;
};
AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{
if (args.ExceptionObject is Exception ex)
{
CrossFirebaseCrashlytics.Current.Log(
$"Fatal: {ex.GetType().Name}: {ex.Message}");
CrossFirebaseCrashlytics.Current.RecordException(ex);
}
};
}
catch (Exception ex)
{
FirebaseInitError = $"{ex.GetType().Name}: {ex.Message}";
System.Diagnostics.Debug.WriteLine($"Firebase init error: {ex}");
}
return true;
}));
#elif ANDROID
events.AddAndroid(android => android.OnCreate((activity, _) =>
{
CrossFirebase.Initialize(
activity,
() => Microsoft.Maui.ApplicationModel.Platform.CurrentActivity,
CreateCrossFirebaseSettings()
);
FirebaseAnalyticsImplementation.Initialize(activity);
}));
#endif
});
builder.Services.AddSingleton(_ => CrossFirebaseAnalytics.Current);
builder.Services.AddSingleton(_ => CrossFirebaseCrashlytics.Current);
#endif
return builder;
}
#if IOS || ANDROID
private static CrossFirebaseSettings CreateCrossFirebaseSettings()
{
return new CrossFirebaseSettings(
isAnalyticsEnabled: true,
isCrashlyticsEnabled: true
);
}
#endif
I am getting the following exception when CrossFirebase.Initialize() is called:
ObjCRuntime.ObjCException: Objective-C exception thrown.
Name: com.firebase.core
Reason: `FirebaseApp.configure()` could not find a valid GoogleService-Info.plist in your project.
Please download one from https://console.firebase.google.com/.
at Firebase.Core.App.Configure()
at Plugin.Firebase.Bundled.Platforms.iOS.CrossFirebase.Initialize(...)
at MDU.MauiProgram...RegisterFirebaseServices...
The important point is that:
The Bundle ID is correct.
GOOGLE_APP_ID and the other Firebase configuration values are correct.
The correct GoogleService-Info.plist is present under the MDU/DDU configuration folders.
I have added it as a BundleResource as suggested.
Firebase Analytics is working and I can see active users in Firebase.
But Crashlytics is not working.
I also previously tried the following configuration because of the iOS Release/Crashlytics symbol issue:
<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<_ExportSymbolsExplicitly>false</_ExportSymbolsExplicitly>
</PropertyGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<_ReferencesLinkerFlags Include="-u __mh_execute_header" />
</ItemGroup>
With this configuration, the application was crashing on startup, so I removed it and changed it to:
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<ReferenceNativeSymbol Include="_mh_execute_header" SymbolType="Function" />
</ItemGroup>
After this change, the application launches, but I am now getting the GoogleService-Info.plist exception above.
Could you please help me understand why Firebase Analytics is working but FirebaseApp.configure() is saying that it cannot find the GoogleService-Info.plist?
Is there any additional configuration required for .NET 10 MAUI iOS when using different GoogleService-Info.plist files for multiple configurations?
Thanks.