【问题标题】:Xamarin.Android - App Center FirebaseInstanceId.get_Instance ErrorXamarin.Android - 应用中心 FirebaseInstanceId.get_Instance 错误
【发布时间】:2020-04-28 01:42:40
【问题描述】:

我的 Xamarin.Android 应用程序在用户打开应用程序后崩溃,我相信它与 Firebase 有关,但我无法弄清楚。如果您对如何解决此错误有任何建议,能否告诉我?

FirebaseInstanceId.get_Instance() Java.Lang.IllegalStateException:默认 FirebaseApp 未在此过程中初始化“应用程序名称”确保首先调用 FirebaseApp.initializeApp(Context)。

JniEnvironment+StaticMethods.CallStaticObjectMethod(Java.Interop.JniObjectReference 类型,Java.Interop.JniMethodInfo 方法,Java.Interop.JniArgumentValue* args) JniPeerMembers+JniStaticMethods.InvokeObjectMethod(System.String encodedMember,Java.Interop.JniArgumentValue* 参数) FirebaseInstanceId.get_Instance () NewUpdateActivity.RunRegistration(System.Collections.Generic.List`1[T] 类别) AsyncMethodBuilderCore+c.b__7_1(System.Object 状态)

【问题讨论】:

  • 错误信息非常明确:Default FirebaseApp is not initialized in this process "App Name" Make sure to call FirebaseApp.initializeApp(Context) first. 你打电话给FirebaseApp.initializeApp(Context)了吗?如果您认为自己做到了,请编辑您的问题以包含 minimum code with which any of us can reproduce the problem(请阅读链接,因为它包含有关如何使某人最有可能提供帮助的有用信息。

标签: firebase xamarin xamarin.android visual-studio-app-center


【解决方案1】:

检查您的 google-services.json 文件构建操作是否为 GoogleServiceJson 如果不起作用,请尝试在 onCreate 方法中自行初始化您的 Firebase,然后再调用任何 Firebase代码。

这是 Firebase 的手动配置。

var options = new FirebaseOptions.Builder()
  .SetApplicationId("<AppID>")
  .SetApiKey("<ApiKey>")
  .SetDatabaseUrl("<DBURl>")
  .SetStorageBucket("<StorageBucket>")
  .SetGcmSenderId("<SenderID>").Build();
  var fapp = FirebaseApp.InitializeApp(this, options);

【讨论】:

  • 感谢您的帮助@Muhammad Adeel Shoukat,我的 google-services.json 文件构建操作设置为 GoogleServicesJson。我应该在 MainActivity.cs 文件的 onCreate 方法底部输入这段代码吗?
  • @Nantourakis 很高兴听到您的问题已经解决。不要忘记接受符合您要求的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-27
  • 1970-01-01
  • 2012-09-29
  • 1970-01-01
  • 2021-02-24
相关资源
最近更新 更多