Unity Firebase 消息传递在 Android 4.1.2 上未初始化



我有一个Unity游戏,我正在使用Firebase消息服务来发送推送通知。

我使用的是 Firebase Unity SDK 3.0.3 版

它适用于我的Galaxy S7,但是当我在运行Android 4.1.2的S2上尝试时,Firebase在初始化它时会抛出异常。

Firebase.Messaging.FirebaseMessaging.TokenReceived += OnTokenReceived;

这是我调用上述代码时来自logcat(adb logcat -s Unity(的日志

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

Firebase 的最低 API 级别显然是 14。上面是4.1.2。

这是半解决方案。(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.
  }
});

相关内容

  • 没有找到相关文章

最新更新