FirebasePushNotificationPlugin
FirebasePushNotificationPlugin copied to clipboard
Default FirebaseApp is not initialized
🐛 Bug Report
Default FirebaseApp is not initialized in this process com.company.app. Make sure to call FirebaseApp.initializeApp(Context) first.
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.
bumping this, is this not a problem for anyone else?
Same for me.
Same here
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 I have tried this and still get the same error
@Aresak I have tried this and still get the same error
Make sure you have the correct bundleId/package name everywhere too.
Checked this and still the same
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 that fixed it for me, thanks!
Same problem. Forms version 4.8.0.1451
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.
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>
I solved the issue adding in the android project the package "Xamarin.Firebase.Common" from Nuget.
@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
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:
- 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).
- Making sure that the package name in the AndroidManifest is the same as one of the Firebase projects in the google-services.json.
- Adding the Merger explicitly to the Android project:
<PropertyGroup> <AndroidManifestMerger>manifestmerger.jar</AndroidManifestMerger> </PropertyGroup>
- 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>
- 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!
In my case it was BuildAction to “GoogleServicesJson” was not appearing.
So I installed the following plugin and 'Voila' it worked. "Xamarin.GooglePlayservices.Basement"
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:
- Cleaned entire solution
- Deleted obj/ and bin/ folders from the Android project.
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>
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.
I am getting same error in VS2022 .Net 8.0