Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp(Context) first
Asked Answered
M

9

18

Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp(Context) first.

i have tried with many things but i am not able to Get notifications in devices.

i also tried with below thing.

In the Properties pane, set the Build Action Select google-services.json in the Solution Explorer window.

In the Properties pane, set the Build Action to GoogleServicesJson (if the GoogleServicesJson build action is not shown, save and close the Solution, then reopen it):to GoogleServicesJson

Notification was working before, but after I update the xamarin forms to 2.5.0.280555 and Xamarin.Firebase.Messaging.42.1021.1, it stopped working .

Musick answered 23/3, 2018 at 14:30 Comment(1)
It happens sometime because package name not matching in google-services.jsonHypophyge
S
27

Make sure:

  1. Package name in AndroidManifest.xml is identical to one in the google-services.json
  2. google-services.json build action is set to GoogleServicesJson
  3. After step 2 restart your IDE & clean & rebuild
  4. Explicitly call FirebaseApp.InitializeApp(Application.Context); in MainActivity.OnCreate just before the LoadApplication(..)
Stillas answered 23/3, 2018 at 14:37 Comment(2)
Thank you very much! steps 1 and 2, first time seeing these instructions anywhere, most information elsewhere just says "add google-services.json to the platform/android folder" and that's it. (smacking my forehead), and it's hit-or-miss whether or not you get clues about step 4.Ebarta
I never got GoogleServicesJson to show up under the Build Actions dropdown in VS2022, and manually inputting it there gave an error. but when I defined it manually within the .csproj it worked fineJablon
D
33

For me, none of the solutions worked that were given anywhere. Only this worked. Just had to downgrade my google services from 4.1.0 to 4.0.0

dependencies {
    classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
    classpath 'com.google.gms:google-services:4.0.0'
    /*classpath 'com.google.gms:google-services:4.1.0' <-- this was the problem */
}

So if you have updated the google services, just try to downgrade or change to an older version. Hope it helps

Disario answered 2/9, 2018 at 10:25 Comment(1)
In my case I had to upgrade to com.google.gms:google-services:4.2.0Anthelion
S
27

Make sure:

  1. Package name in AndroidManifest.xml is identical to one in the google-services.json
  2. google-services.json build action is set to GoogleServicesJson
  3. After step 2 restart your IDE & clean & rebuild
  4. Explicitly call FirebaseApp.InitializeApp(Application.Context); in MainActivity.OnCreate just before the LoadApplication(..)
Stillas answered 23/3, 2018 at 14:37 Comment(2)
Thank you very much! steps 1 and 2, first time seeing these instructions anywhere, most information elsewhere just says "add google-services.json to the platform/android folder" and that's it. (smacking my forehead), and it's hit-or-miss whether or not you get clues about step 4.Ebarta
I never got GoogleServicesJson to show up under the Build Actions dropdown in VS2022, and manually inputting it there gave an error. but when I defined it manually within the .csproj it worked fineJablon
L
25

Add the plugin to the build.gradle (app level)

// ADD THIS AT THE BOTTOM

apply plugin: 'com.google.gms.google-services'
Lorenzoloresz answered 14/9, 2018 at 19:42 Comment(1)
I was able to run my app with Firebase just fine but after force closing and restarting I was getting this crash. Adding the apply plugin at the bottom of my build.gradle fixed the crash.Impair
T
3

for me, that happen when I forgot add the second plugin in the app module

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'  // Google Services plugin

after add this plug in, you can try the other's suggestions.

Tarnation answered 29/4, 2021 at 17:8 Comment(0)
O
0

Upgrade com.google.gms:google-services to latest version, it will be solved.

Oaf answered 18/9, 2020 at 16:2 Comment(0)
G
0

Upgrade

com.google.gms:google-services

to latest version, it will be solved.

It works for me.

Guanidine answered 16/3, 2021 at 5:52 Comment(0)
L
0

i've recently had this problem and found a solution that worked for me:

i've been developing for net7.0-android33.0 and i just realized that I had added in my .csproj an specific PropertyGroup Condition for that targetFramework where i had set a different ApplicationId.

My Google-Services.json was created with the previous ApplicationId so i've generated a new one in Firebase with the correct ApplicationId and it worked.

Maybe it's a bit silly but i've been stuck on this for a couple days so it may help someone

Lessard answered 7/9, 2023 at 15:2 Comment(0)
D
0

In my case it fails before reaching OnCreate(), for CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);

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)
    {
        builder.ConfigureLifecycleEvents(events =>
        {
            events.AddAndroid(android => android.OnCreate((activity, _) =>
                CrossFirebase.Initialize(activity, CreateCrossFirebaseSettings())));
            CrossFirebaseCrashlytics.Current.SetCrashlyticsCollectionEnabled(true);
        });

        builder.Services.AddSingleton(_ => CrossFirebaseAuth.Current);
        return builder;
    }

    private static CrossFirebaseSettings CreateCrossFirebaseSettings()
    {
        return new CrossFirebaseSettings(isAuthEnabled: true,
        isCloudMessagingEnabled: true, isAnalyticsEnabled: true);
    }
}
Discant answered 4/3 at 20:3 Comment(0)
V
0

If you are using expo, you need to prebuild your app before running it.

 npx expo prebuild --platform android  --clean
Viridi answered 23/5 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.