3

I've looked at every question on the net regarding this bug. It seams to have been very common with versions < 42.1021.1. But I have the newest version and the bug is still occurring.

I have added my google-services.json and selected the appropriate build action. I have tried the clean and rebuild with no success. I also tried workarounds for the bugs in other versions like adding the Target tag in the csproj file. I've tried manually entering the strings from the json.

Whatever I do calling FirebaseApp.InitializeApp(this) returns null and when I try to reference FirebaseInstanceId.Instance.Token I get the very common exception:

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

Github and Xamarin forums say this was fixed with 60.1141.1, it never was. I also went through my csproj to ensure all references to GoogleServices were for the newest version.

I have no idea why this won't work and I really need this soon for work. Please help if you can.

I've looked at the following resources with no success: Getting Exception Using Firebase in Xamarin Android https://learn.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=vswin https://bugzilla.xamarin.com/show_bug.cgi?id=56108#c1 Default FirebaseApp is not initialized https://forums.xamarin.com/discussion/94464/firebase-cloud-messaging-app-not-initialized Xamarin.android Default FirebaseApp is not initialized in this process

and more I can't track down. Why is this bug still occurring on this version????

tantonj
  • 434
  • 5
  • 18

3 Answers3

3

I had the same problem and after some investigation I've tried to initiate it manually in the OnCreate-method in that way

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

  LoadApplication(App);

  PushNotificationManager.ProcessIntent(this, Intent);

That worked for me and it seems that the build process "GoogleServiceJson" doesn't work which should does it instead. Best regards, Thomas

ThomasL
  • 111
  • 3
  • I'm using Plugin.FirebasePushNotification and I had this problem, after three days of headache I have used your solution and my app is working again! Thank you! – Elelio Nov 27 '19 at 10:44
1

In my problem, the package names were different. Check the package name in AndroidManifest.xml is the same in the google-services.json.

Akif
  • 7,098
  • 7
  • 27
  • 53
  • 3
    Any reason for you question mark? Are you saying to check the package name or asking if you should check the package name? – Scratte Dec 10 '20 at 13:13
  • Please don't write answers in a way that makes them look like questions. There are systems in place to check for Not An Answer (NAA) posts. This answer was falsely picked up by one of them. Please consider editing it to look more like an answer. – Sabito stands with Ukraine Dec 10 '20 at 20:58
0

I discovered my issue! After creating a dummy project with nothing but Firebase initialization it worked perfectly (using the same google-services.json). This was able to initialize just fine.

After comparing the projects I noticed the previous developer had the application name defined in strings under the name "app_name". Once I made another string under "ApplicationName" and had it match up with the label in my launch activity and the manifest application tag I was able to initialize.

Additionally, my launch activity was inheriting AppCompatActivity instead of Activity. Prior to finding the above solution I created a splash page which inherits activity, this is where I initialized Firebase. Not sure if this was required for solution or not.

tantonj
  • 434
  • 5
  • 18
  • I've got the same Issue on Xamarin Forms. Can you explain a bit more about the app_name - not sure where I check that in the Xamarin Forms – Peter Kerr Jun 08 '18 at 16:52
  • So I'm not actually sure if this really was the solution now. My dummy project (which was working) had in the Strings.xml the app name under "ApplicationName". While the project which failed to work had the app name under "app_name" -> from the previous developers. Once I changed this to ApplicationName, made sure that this value was equal to the label for the launch Activity and equal to the label in the application tag in the manifest it worked. However, on the dummy project once I changed the name of this value in Strings.xml the dummy project still worked. Very confusing. – tantonj Jun 11 '18 at 13:33
  • It should also be noted these were not Xamarin Forms projects. – tantonj Jun 11 '18 at 13:34
  • I am also facing this issue. Tried your solution but didn't work, – fhnaseer Jun 22 '18 at 23:31