首页 > 解决方案 > 将 Xamarin 表单链接到 Firestore

问题描述

我在将 Xamarin Forms 链接到 Firestore 时遇到问题。我在 Firebase 的 Firestore 数据库中有一个名为 Candidates 的集合,我正在使用 Plugin.CloudFirestore nuget 来链接 Firestore 和 Xamarin Forms

我尝试在以下链接中使用“获取”示例:

https://github.com/f-miyu/Plugin.CloudFirestore

        var query = await CrossCloudFirestore.Current
                                    .Instance
                                    .GetCollection("Candidates")
                                    .GetDocumentsAsync();


        var documents = query.ToObjects<Candidate>();

当我运行代码时,我收到以下消息

“未处理的异常:Java.Lang.IllegalStateException:名称为 [FirebasePlugin] 的 FirebaseApp 不存在。”

关于出了什么问题的任何想法?

标签: firebasexamarin.formsgoogle-cloud-firestore

解决方案


您是否按照说明进行操作?

  • 将 google-services.json 添加到 Android 项目。选择 GoogleServicesJson 作为构建操作。(如果无法选择 GoogleServicesJson,请重新加载此 android 项目。)
  • 目标框架必须是 Android 9.0 (Pie)。如果您使用其他库、Xamarin.Forms 等,则需要启用 Multi-Dex。

    <TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
    <AndroidEnableMultiDex>true</AndroidEnableMultiDex>
    

https://github.com/f-miyu/Plugin.CloudFirestore#android


推荐阅读