Guye Incognito
Guye Incognito

Reputation: 2830

Unity Firebase messaging not initialising on Android 4.1.2

I have a Unity game in which I am using the Firebase messaging service in order to send push notifications for.

I'm using the Firebase Unity SDK version 3.0.3

It works on my Galaxy S7, but when I try it on my S2 running Android 4.1.2 Firebase throws an exception when I initialise it.

Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;

Here are the logs from logcat (adb logcat -s Unity) when I call the above code

I/Unity   ( 8751): Firebase App initializing app com.ARTEFICER.fruitfall (default 1).
I/Unity   ( 8751): InitializationException:  Firebase modules failed to initialize: messaging (missing dependency)
I/Unity   ( 8751):   at Firebase.FirebaseApp.CreateAndTrack (Firebase.CreateDelegate createDelegate) [0x00000] in <filename unknown>:0
I/Unity   ( 8751):   at Firebase.FirebaseApp.Create () [0x00000] in <filename unknown>:0
I/Unity   ( 8751):   at Firebase.FirebaseApp.get_DefaultInstance () [0x00000] in <filename unknown>:0
I/Unity   ( 8751):   at Firebase.Messaging.FirebaseMessaging+Listener..ctor () [0x00000] in <filename unknown>:0
I/Unity   ( 8751):   at Firebase.Messaging.FirebaseMessaging+Listener.Create () [0x00000] in <filename unknown>:0
I/Unity   ( 8751):   at Firebase.Messaging.FirebaseMessaging..cctor () [0x00000] in <filename unknown>:0
I/Unity   ( 8751): Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Firebase.Messaging.FirebaseMessaging
I/Unity   ( 8751):   at FireBaseSetup.Start () [0x00000] in <filename unknown>:0

The minimum API level for Firebase is apparently 14. Which 4.1.2 is above.

Upvotes: 1

Views: 981

Answers (1)

Mopto
Mopto

Reputation: 390

Here's semi solution. (https://firebase.google.com/docs/cloud-messaging/unity/client)

Firebase.FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => {
  var dependencyStatus = task.Result;
  if (dependencyStatus == Firebase.DependencyStatus.Available) {
    // Create and hold a reference to your FirebaseApp,
    // where app is a Firebase.FirebaseApp property of your application class.
    Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;

    // Set a flag here to indicate whether Firebase is ready to use by your app.
  } else {
    UnityEngine.Debug.LogError(System.String.Format(
      "Could not resolve all Firebase dependencies: {0}", dependencyStatus));
    // Firebase Unity SDK is not safe to use here.
  }
});

Upvotes: 1

Related Questions