首页 > 解决方案 > 无法连接到 Cordova 应用上的 Cloud Firestore 数据库

问题描述

我正在尝试使用 Cordova 构建一个应用程序,我想在其中连接 Google Cloud Firestore 数据库。

我使用Cordova Firestore 插件并遵循安装步骤(添加 google-services.json、安装依赖项等)。为了了解如何使用该插件,我构建了我的应用程序并将其与 Chrome DevTools 连接以使用控制台。

当我尝试通过控制台从 firestore 获取数据时,如插件示例中所述,我总是收到以下错误:

Attempt to invoke virtual method 'com.google.firebase.firestore.CollectionReference com.google.firebase.firestore.FirebaseFirestore.collection(java.lang.String)' on a null object reference

我在谷歌上搜索并找到了将版本更改com.google.gms:google-services为 minimum的提示3.1.1

我能做些什么?

标签: cordovagoogle-cloud-firestorecordova-plugins

解决方案


实际上我遇到了同样的问题并在这里找到了解决方案:

https://github.com/ReallySmallSoftware/cordova-plugin-firestore/issues/11#issuecomment-453435050

通过注释掉 config{}: 这使得浏览器和 android 平台都可以工作(尚未在 iOS 上测试)

这里更新的例子:

https://github.com/ReallySmallSoftware/cordova-plugin-firestore/issues/13#issuecomment-467531402

var options = {
    "datePrefix": '__DATE:',
    "fieldValueDelete": "__DELETE",
    "fieldValueServerTimestamp" : "__SERVERTIMESTAMP",
    "persist": true,
//  "config" : {}
};

推荐阅读