Daniel Jerome
Daniel Jerome

Reputation: 301

Firebase push notification - Default FirebaseApp is not initialized in this process

I am struggling to implement Google's Firebase push notifications in a mature MVVMcross application. We are being forced to seek a new solution to our current one because it appears that the functionality is about to be deprecated in AppCenter.

We've placed the code inside the RootActivity file (at the bottom of the method)

protected override void OnCreate(Bundle bundle)

When I run the app in a USB/debug scenario on my Android Galaxy I get the current error "Default FirebaseApp is not initialized in this process"

I tried to use the approach that was recommended in the error message to no avail:

FirebaseApp.InitializeApp(RootActivity.Context);
FirebaseMessaging.Instance.GetToken().AddOnCompleteListener(new OnCompleteListener());
        

In case anyone is wondering here is the code for the method that is mentioned above was setup for testing purposes using a breakpoint:

public class OnCompleteListener : Java.Lang.Object, IOnCompleteListener
        {
            public void OnComplete(Android.Gms.Tasks.Task task)
            {
                var token = task.Result.ToString();
            }
        }

We initially tested this in a standard Xamarin Forms Android app for testing and didn't have any problem with getting the token but we hit the wall when we played with it in our client's MVVMcross app.

I would also like to mention that I have tried the following solution with no luck as well:

var setupSingleton = MvxAndroidSetupSingleton.EnsureSingletonAvailable(Context);
setupSingleton.EnsureInitialized();
FirebaseMessaging.Instance.GetToken().AddOnCompleteListener(new OnCompleteListener());
        

Upvotes: 2

Views: 406

Answers (1)

Daniel Jerome
Daniel Jerome

Reputation: 301

I found that I had two problems. The first one was the fact that my project name did not match in my manifest and google services key. I was using my own key that I setup for testing. After I realized this I switched back to my client's key and double checked that it was part of the build. As soon as I resolved that issue I found that I needed to install the nuget package for Xamarin.Google.Dagger to resolve the reflection issues. After taking care of that I did a clean/rebuild and ran the debug on my Galaxy S20 test device. This fix allowed me to hit my test break point that I setup for testing the token reception from FCM.

Upvotes: 1

Related Questions