1

I am having issues doing anything with Firebase, I have followed about 4 different guides online and I am still getting the error listed above. Please see my project and resource details below

MauiProgram.cs

            builder.ConfigureLifecycleEvents(events =>
            {
                events.AddAndroid(android => android.OnCreate((activity, _) => FirebaseApp.InitializeApp(activity)));
            });

.csproj Application Id and Google Service Json Refr

<!-- App Identifier -->
<ApplicationId>com.dev.testapp</ApplicationId>

<!-- This file is in the root of my project not Platforms/Android/ -->
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-android'">
    <GoogleServicesJson Include="google-services.json" />
</ItemGroup>   

In the google-services.json file, the package_name and bundle_id are the same and also match the applicationId I stated above. Any help is much appreciated this is frustrating.

steve
  • 797
  • 1
  • 9
  • 27

2 Answers2

1

Found a similar issue on Github.Default FirebaseApp is not initialized #357. Many comment suggests to set the Build action of google-services.json to GoogleServicesJson. So you may install Xamarin.GooglePlayservices.Base Nuget. Don't forget to clean your project.

Also, you could check this thread: Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp(Context) first. EvZ's answer give some suggestions.

Hope it works for you.

Liqun Shen-MSFT
  • 3,490
  • 2
  • 3
  • 11
0

In case anybody finds this and is using .net7.0 as well. I could solve it with this website.

[https://dev.to/vhugogarcia/firebase-analytics-in-net-maui-4p6d][1]

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-android'">
      <GoogleServicesJson Include="google-services.json" />
      <PackageReference Include="Xamarin.Firebase.Core" Version="121.1.1" />
</ItemGroup>

Basically installed Xamarin.Firebase.Core and initialized it in MauiProgram.cs

by adding the method:

private static MauiAppBuilder RegisterFirebase(this MauiAppBuilder builder)
    {
        builder.ConfigureLifecycleEvents(events =>
        {
#if IOS
            events.AddiOS(iOS => iOS.FinishedLaunching((app, launchOptions) => {
                Firebase.Core.App.Configure();
                return false;
            }));
#else
            events.AddAndroid(android => android.OnCreate((activity, bundle) => {
                Firebase.FirebaseApp.InitializeApp(activity);
            }));
#endif
        });

        return builder;
    }

Then on the static CreateMauiApp method register the Firebase Services:

builder.RegisterFirebase();
SunnySonic
  • 1,318
  • 11
  • 37