Firebase Initialization failure

Joshua Tanton 1 Reputation point
2022-06-09T16:12:36.733+00:00

My Xamarin project required I update a nuget package to fix a certain feature. This update required I update my mono version, which required I update to vs 2022. After doing so I had update multiple nuget packages including firebase. (however this problem was occurring before updating my firebase nuget packages).

When I execute the following:
FirebaseApp fa = FirebaseApp.InitializeApp(Application.Context);
fa is null. My app crashes whenever trying to access the firebase token and gives me the app is not initialized error. I've been troubleshooting this for over 2 days with no success.

I've updated the setting for the firebase app to include the new debug.keystore sha-1 fingerprint and update my google-services.json. My google-services.json is included in the project and it's build action is set to GoogleServicesJson. I haven't changed anything with my code base relating to firebase setup and it was working before this migration. I've confirmed this isn't due to the fingerprint not being added as I've added the new one for the debug.keystore for xamarin as well as trying with my release keystore which is already added and is currently working with an older build of the app on production.

The logcat tells me that "FirebaseApp initialization unsuccessful" when I try to initialize it. The package name is accurate and matches the google-services.json.

I've looked for others with this problem for days and every solution I've found was either already implemented or I have tried with no effect.

I should note one other change to my project that was necessary for the aforementioned nuget update. I've changed my target version to Android 12 (S), (It was previously 9 (Q))

I've attached screenshots showing my firebase and google nuget packages, the firebase app not initializing, and my google-services.json with the correct build action set.

Any help here would be greatly appreciated.209924-fb1.png209974-fb2.png209925-fb3.png209982-fb5.png

Thanks,

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Joshua Tanton 1 Reputation point
    2022-06-10T21:33:08.143+00:00

    To give an update on this.

    I've found the following old bug from many many versions ago https://bugzilla.xamarin.com/56/56108/bug.html

    I think this is what is affecting my project. I've looked now in my Resources.designer.cs. and indeed the gcm_defaultSenderId, google_api_key, and google_app_id values are not being created in there on build.

    The bug says this is the responsibility of Xamarin.GooglePlayServices.Basement nuget package. Which you can see in the screenshots I currently have fully updated. I've downgraded it to the same version I had before this was happening. cleaned project. deleted obj/bin folder, deleted Resource.designer.cs (to ensure a new one is generated). Yet still this happens, no values places in the resource designer as it should be.

    However this bug was for a much older version which was apparently fixed. So I have no idea why it's not working.

    I should also note that when adding in gcm_defaultSenderId google_api_key google_app_id and project_id manually in Strings.xml the firebase object initializes correctly. I can also get this to initialize correctly by adding these parameters into options when initializing the firebaseapp.

    However, This is not a valid solution as the Token of the created object is still null!

    Why?

    Update

    The reason why is I was expecting it to work the same as the older version. You now have to call FirebaseMessaging.Instance.GetToken(). I have also had to add anOnCompleteListener to insure the token is received. Once this method executes the result is dumped into the same location as before: FirebaseInstanceId.Instance.Token. Where as in an older version the token would immediately be generated after firebaseapp initialization. This is no longer the case.

    My initial problem still stands, though I have this workaround I would really prefer the compiler is correctly adding the parameters from google-services.json into the Resource.designer.cs

    0 comments No comments