FirebasePushNotificationPlugin icon indicating copy to clipboard operation
FirebasePushNotificationPlugin copied to clipboard

Default FirebaseApp is not initialized

Open mohammedmsadiq opened this issue 3 years ago • 21 comments

🐛 Bug Report

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

mohammedmsadiq avatar Sep 10 '20 08:09 mohammedmsadiq

seeing this as well on latest builds. (targeting android 30)

Xamarin Forms: 4.8.0.1364 Plugin.FirebasePushNotification: 3.3.10

I saw another thread in here posted which some people mentioned cleaning the solution none of it worked for me.

B2alex avatar Sep 10 '20 22:09 B2alex

bumping this, is this not a problem for anyone else?

B2alex avatar Sep 14 '20 22:09 B2alex

Same for me.

AshishInnovantes avatar Sep 15 '20 08:09 AshishInnovantes

Same here

IncreaseComputers avatar Sep 15 '20 10:09 IncreaseComputers

Same for me.

For a workaround use this before initializing the plugin:

FirebaseApp.InitializeApp(
      this,
      new FirebaseOptions.Builder()
      .SetApplicationId("<AppID>")
      .SetApiKey("<APIKey>")
      .SetDatabaseUrl("https://<url>.firebaseio.com")
      .SetStorageBucket("*.appspot.com")
      .SetGcmSenderId("<senderID")
      .Build()
);

Aresak avatar Sep 17 '20 12:09 Aresak

@Aresak I have tried this and still get the same error

IncreaseComputers avatar Sep 17 '20 13:09 IncreaseComputers

@Aresak I have tried this and still get the same error

Make sure you have the correct bundleId/package name everywhere too.

Aresak avatar Sep 17 '20 13:09 Aresak

Checked this and still the same

IncreaseComputers avatar Sep 17 '20 15:09 IncreaseComputers

For me, that seemed to be linked to my google-services.json file not having the right build as dropdown. To be more accurate, I hadn't the right option. What did the trick for me :

  • install the nuget GooglePlayServices.base
  • close and reopen my solution
  • set the google-services.json file to the correct build as option

Then the default firebaseapp error disappeared

thibautvdu avatar Sep 17 '20 16:09 thibautvdu

@thibautvdu that fixed it for me, thanks!

B2alex avatar Sep 19 '20 16:09 B2alex

Same problem. Forms version 4.8.0.1451

JustickDM avatar Sep 23 '20 14:09 JustickDM

Same issue. Xamarin Forms 4.8.0.1534. @thibautvdu this isn't a solution for me because that nuget package isn't compatible with newer versions of Xamarim. I'm going to try downgrading.

ScottishRoss avatar Oct 11 '20 13:10 ScottishRoss

have same error, tried everything except installing GooglePlayService.Base because it's not compatible with newer versions even manually entry in my .csproj file

<ItemGroup>
    <GoogleServicesJson Include="google-services.json" />
 </ItemGroup>

Cvijo avatar Nov 18 '20 17:11 Cvijo

I solved the issue adding in the android project the package "Xamarin.Firebase.Common" from Nuget.

carlosanpardo avatar Dec 21 '20 14:12 carlosanpardo

@thibautvdu install this NuGet Xamarin.GooglePlayServices.Basement Version 71.1620.4 worked for me without integration with Android X @Cvijo, and you don't need to install all Firebase common library @carlosanpardo

AbuMandour avatar Dec 27 '20 18:12 AbuMandour

After a couple of days of Firebase related errors, here's a list of things that helped:

1. For "the FirebaseApp is not initialized error": in my case, simply calling the FirebaseApp.InitializeApp(this) prior to initializing this plugin resolved the error for me. This step is NOT in the sample project.

2. But the issue that kept me guessing and finding all possible solutions was that the Initialize method returned null reference exception (or "Attempt to invoke virtual method 'void com.google.firebase.iid.FirebaseInstanceId.zzb(boolean)' on a null object reference").

What actually helped after all:

  1. Making sure that the google-services.json is added with the correct build action: GoogleServicesJson (it's available when the Xamarin.GooglePlayServices.Base nuget is installed).
  2. Making sure that the package name in the AndroidManifest is the same as one of the Firebase projects in the google-services.json.
  3. Adding the Merger explicitly to the Android project: <PropertyGroup> <AndroidManifestMerger>manifestmerger.jar</AndroidManifestMerger> </PropertyGroup>
  4. Deleting dated (and deprecated) nodes from the AndroidManifest.xml. For example these are not needed when using the plugin:

<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
 <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
 <intent-filter>
 <action android:name="com.google.android.c2dm.intent.RECEIVE" />
 <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
 <category android:name="${applicationId}" />
 </intent-filter>
 </receiver>

  1. THE MOST IMPORTANT FOR ME WAS THIS: Previously I had this in the AndroidManifest.xml, but this entry kept the merger from doing its job: tools:node="replace"

This change was found on the Firebase issues section and finally solved the issue. Replace the above with this: tools:node="merge" tools:replace="android:name, android:theme, android:label, android:icon, android:roundIcon android:allowBackup" (You might not need every setting after the "replace", but the main ones are "name, theme, label, icon". I had to set the android:roundIcon as well in my case and include it in the tools:replace)

Hope this helps somebody with similar problem. Have a nice day!

OlegZhXam avatar Jan 20 '21 10:01 OlegZhXam

In my case it was BuildAction to “GoogleServicesJson” was not appearing.

So I installed the following plugin and 'Voila' it worked. "Xamarin.GooglePlayservices.Basement"

AshishInnovantes avatar Feb 10 '21 07:02 AshishInnovantes

Installing Xamarin.GooglePlayServices.Base did not help. I read https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=macos#firebaseapp-is-not-initialized which indicates you should Clean and Rebuild the project.

What worked for me was the simple:

  1. Cleaned entire solution
  2. Deleted obj/ and bin/ folders from the Android project.

Meekohi avatar May 12 '21 19:05 Meekohi

I got this error when I remove the PackageReference to Xamarin.GooglePlayServices.Basement in the Xamarin.Android project. These two PackageReferences are now part of my Xamarin.Android project:

    <PackageReference Include="Plugin.FirebasePushNotification">
      <Version>3.3.10</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.GooglePlayServices.Basement">
      <Version>117.6.0</Version>
    </PackageReference>

thomasgalliker avatar Jul 28 '21 14:07 thomasgalliker

Modify the requestPermissions in PushNotification.configure to false to solve this error. At least it is valid for version 0.69. I hope it can help you.

tanyicheng avatar Jul 29 '23 12:07 tanyicheng

I am getting same error in VS2022 .Net 8.0

mrnams avatar Mar 01 '24 18:03 mrnams