【问题标题】:Xamarin.android Default FirebaseApp is not initialized in this processXamarin.android 默认 FirebaseApp 未在此过程中初始化
【发布时间】:2017-10-25 00:23:56
【问题描述】:

我面临从 firebase 获取令牌的问题(推送通知)

Default FirebaseApp is not initialized in this process com.ready_apps.Nebka.Business. Make sure to call FirebaseApp.initializeApp(Context) first.

即使我调用了 FirebaseApp.InitializeApp(this);在很多地方

MyApplication(扩展应用程序),在我调用FirebaseInstanceId.Instance?.Token;的Activity的onCreate中

【问题讨论】:

    标签: android firebase push-notification xamarin.android firebase-cloud-messaging


    【解决方案1】:

    编辑:此错误已在 Xamarin.Firebase 版本 57.1104.0-beta1 中修复。

    此错误似乎出现在较新版本的 Firebase for Xamarin 中。我今天也遇到了这个错误,使用的是最新的稳定版本 42.1021.1。 (该错误也出现在最新的 beta 版本中)。

    我发现已针对问题 here 提交了错误报告。

    如错误报告中所述,删除 Android 项目中的 /obj 和 /bin 文件夹,和/或在 Visual Studio 中清理项目应该可以暂时解决问题,直到您更新任何会更改 Resource.Designer 的资源.cs 文件。

    在永久解决方案可用之前,也可以降级到旧版本的 Firebase 和 Google Play 服务。例如,我在 Firebase 和 Google Play Services 版本 32.961.0 上没有遇到此错误。

    【讨论】:

    • 我最近从 GCM 升级到 FCM,我发誓一切都变得更糟了。很烦人!
    • 我也遇到了这个问题,即使我尝试降级Google play服务版本也不起作用
    【解决方案2】:

    只需清理一次解决方案,然后再次运行应用程序。

    此错误已报告给 Xamarin。 https://bugzilla.xamarin.com/show_bug.cgi?id=56108

    此解决方案在他们的评论线程中提供,它可能会在较新版本的 xamarin NuGet 包中得到修复。

    【讨论】:

      【解决方案3】:

      我没有修复它,但我发现只能在调试模式下解决这个问题

      我在活动中调用了这个方法 onCreate() 我需要请求令牌

      FirebaseInstanceId.Instance?.Token
      

      方法如下

      private void ConfigureFireBase()
              {
      
      #if DEBUG
                  try
                  {
                  Task.Run(() =>
                  {
                      var instanceId = FirebaseInstanceId.Instance;
                      instanceId?.DeleteInstanceId();
                      //Log.Debug("TAG", "{0} {1}", instanceId?.Token?.ToString(), instanceId.GetToken(GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));
      
                  });
      
                   // For debug mode only - will accept the HTTPS certificate of Test/Dev server, as the HTTPS certificate is invalid /not trusted
                  ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;
                  }catch (Exception e)
                  {
                      Log.Debug("TAG", e.Message);
                  }
      #endif
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-01-30
        • 2019-07-05
        • 1970-01-01
        • 2020-08-16
        • 1970-01-01
        • 1970-01-01
        • 2019-02-06
        • 1970-01-01
        相关资源
        最近更新 更多