【问题标题】:Firebase collection.where not working on real Android deviceFirebase collection.where 不适用于真正的 Android 设备
【发布时间】:2021-06-24 00:42:43
【问题描述】:

我的应用程序使用 FireBase,用于身份验证和存储数据。 如果我在模拟器上尝试我的应用程序,或者连接设备并在调试模式下运行,firebase collection.where 工作正常,获取数据等。 但是,如果我制作了一个 aab/apk,并将其安装在同一设备上,则会出现错误: 不良状态:无元素。 有人有同样的错误吗? 感谢您的帮助!!!

代码是:

Future<User> getLoggedInUserData(String userId) async {
    //try {
      FS.QuerySnapshot q = await collection
          .where('uid', isEqualTo: userId)
          .get();
      EasyLoading.showToast(q.docs.isEmpty.toString());
      FS.DocumentSnapshot d = await q.docs.first;
      FS.DocumentSnapshot document = await collection.doc(d.id).get();
      return User.fromSnapshot(document);
    //}catch(e){
    //  EasyLoading.showToast(e.toString());
    //}
  }

如果我在模拟器或连接的设备上运行它,它工作正常,当我制作一个 apk 时,将它安装到同一设备上,QuerySnapshot "q" 为空。请帮忙!!!

【问题讨论】:

  • 您是否将 SHA 密钥添加到 Firebase 控制台?您是在构建发布版还是在调试 APK?
  • 我构建发布 APK
  • 未添加 SHA 密钥
  • 尝试添加sha键。

标签: android firebase flutter google-cloud-firestore device


【解决方案1】:

终于... 关键是梯度。 因为我用过的一些包需要 android/build.gradle 中的类路径 'com.android.tools.build:gradle:3.6.4' (我不能使用 build:gradle:4.1.2) 并且 build:gradle:3.6.4 不适用于 gardle 发行版 6.7,只需在 app/gradle/wrapper/gradle-wrapper.properties 中将发行版更改为 5.6.4 即可!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-15
    相关资源
    最近更新 更多