Java.Lang.IllegalStateException默认FirebaseApp未初始化

时间:2020-05-02 02:27:01

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

我在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”

1 个答案:

答案 0 :(得分:0)