【问题标题】:Java.Lang.IllegalStateException Default FirebaseApp is not initializedJava.Lang.IllegalStateException 默认 FirebaseApp 未初始化
【发布时间】:2020-08-16 14:32:50
【问题描述】:

我在 Visual Studio 2019 中有一个 Xamarin Forms 解决方案。我现在只使用 Android 版本。完整的错误是:

Java.Lang.IllegalStateException Message=默认 FirebaseApp 不是 在这个过程中初始化appcardview.sample.android。确保 首先调用 FirebaseApp.initializeApp(Context)。

在我的 Android 项目中,我正在尝试连接到 Firebase 身份验证。我已经添加了我的 google-services.json。我在网上看到应该添加为:

<ItemGroup>
    <GoogleServicesJson Include="google-services.json" />
</ItemGroup>

但这给了我一个错误,告诉我 GoogleServicesJson 无法识别,所以我将它添加到我的 .csproj 文件中

  <ItemGroup>
    <None Include="google-services.json" />
    <None Include="Resources\AboutResources.txt" />
    <None Include="Assets\AboutAssets.txt" />
    <None Include="Properties\AndroidManifest.xml" />
  </ItemGroup>

1-我还在android项目的MainActivity类的onCreate方法的开头添加了以下行;我已将它添加到我的 onCreate 的开头,也许我需要将它放在其他地方?:

FirebaseApp.InitializeApp(Application.Context);

2-问题可能是我在 .csproj 文件中添加它的方式吗?

3-有人还提到了以下内容,我不确定这意味着什么或我应该改变什么,也许这就是问题所在?

确保您的包名与包名相同 在“google-services.json”中

【问题讨论】:

    标签: c# firebase xamarin xamarin.forms firebase-authentication


    【解决方案1】:

    我终于想通了,我只需要按照这里的步骤操作:

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

    旁注:对于第 2 步,另一篇文章解释了如何执行此操作:

    https://forums.xamarin.com/discussion/175159/i-didnt-find-googleservices-json-in-the-build-action

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-30
      • 1970-01-01
      • 2022-10-05
      • 1970-01-01
      • 2017-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多