所以我写这篇文章是为了以防万一有人有什么 idea .我不能让Firebase/FiRestore在我的Android模拟器上与我的Ffltter项目一起工作.

在这一点上,我要做的就是匿名登录,并通过在终端中打印一些东西来判断文档是否存在,以确认我的应用程序是否在骨架应用程序中连接到Firebase/FiRestore.

  firebase_auth: ^3.7.0
  cloud_firestore: ^3.4.6
  firebase_core: ^1.21.1

匿名登录.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp();
  await FirebaseAuth.instance.signInAnonymously();

  runApp(const MyApp());
}
...

并调用此方法来告诉我文档是否存在(确实存在).

Future testFirebase() async {
  await FirebaseFirestore.instance
      .collection("fruit")
      .doc("peach")
      .get()
      .then((document) {
    if (document.exists) {
      print("exists");
    } else {
      print("does not exist");
    }
  });
}

这样做会导致应用程序挂起.然后大约5分钟后,我收到一系列错误消息

W/System  (13182): Ignoring header X-Firebase-Locale because its value was null.
D/FirebaseAuth(13182): Notifying id token listeners about user ( fUMAwRpjESeaRik9ABkzTNE7bH92 ).
D/FirebaseAuth(13182): Notifying auth state listeners about user ( fUMAwRpjESeaRik9ABkzTNE7bH92 ).
W/DynamiteModule(13182): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule(13182): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller(13182): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
I/flutterconntes(13182): The ClassLoaderContext is a special shared library.
I/chatty  (13182): uid=10156(com.example.flutterconntest) AsyncTask #1 identical 1 line
I/flutterconntes(13182): The ClassLoaderContext is a special shared library.
D/nativeloader(13182): classloader namespace configured for unbundled product apk. library_path=/product/priv-app/PrebuiltGmsCore/lib/x86:/product/priv-app/PrebuiltGmsCore/PrebuiltGmsCore.apk!/lib/x86:/product/lib:/system/product/lib
W/ProviderInstaller(13182): Failed to report request stats: com.google.android.gms.common.security.ProviderInstallerImpl.reportRequestStats [class android.content.Context, long, long]
W/flutterconntes(13182): Accessing hidden field Ldalvik/system/BaseDexClassLoader;->pathList:Ldalvik/system/DexPathList; (greylist, reflection, allowed)
W/flutterconntes(13182): Accessing hidden field Ldalvik/system/DexPathList;->nativeLibraryDirectories:Ljava/util/List; (greylist, reflection, allowed)
W/flutterconntes(13182): Accessing hidden field Ldalvik/system/DexPathList;->systemNativeLibraryDirectories:Ljava/util/List; (greylist, reflection, allowed)
W/flutterconntes(13182): Accessing hidden field Ldalvik/system/DexPathList;->nativeLibraryPathElements:[Ldalvik/system/DexPathList$NativeLibraryElement; (greylist, reflection, allowed)
W/flutterconntes(13182): Accessing hidden method Ldalvik/system/DexPathList;->makePathElements(Ljava/util/List;)[Ldalvik/system/DexPathList$NativeLibraryElement; (greylist, reflection, allowed)
V/NativeCrypto(13182): Registering com/google/android/gms/org/conscrypt/NativeCrypto's 286 native methods...
W/flutterconntes(13182): Accessing hidden method Ljava/security/spec/ECParameterSpec;->getCurveName()Ljava/lang/String; (greylist, reflection, allowed)
I/ProviderInstaller(13182): Installed default security provider GmsCore_OpenSSL
I/TetheringManager(13182): registerTetheringEventCallback:com.example.flutterconntest
W/Firestore(13182): (24.2.2) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
W/Firestore(13182):
W/Firestore(13182): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
W/Firestore(13182): (24.2.2) [WatchStream]: (9bc0685) Stream closed with status: Status{code=UNAVAILABLE, description=Channel shutdownNow invoked, cause=null}.
W/DynamiteModule(13182): Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule(13182): Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller(13182): Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
W/ProviderInstaller(13182): Failed to report request stats: com.google.android.gms.common.security.ProviderInstallerImpl.reportRequestStats [class android.content.Context, long, long]

然而,在我运行Android Go和Android 12的实体设备上,它运行得非常完美.

我有:

  • 通过打开Chrome/Maps/etc判断Android仿真器是否有互联网连接,它们都工作正常
  • 在androidManifest主调试中添加了<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />(&A)
  • 已重新安装Windows
  • 已重新安装Ffltter、Android SDK、Android Studio、VSCode,请仔细按照指南进行操作,以确保一切配置正确
  • 套装minSdkVersion 22
  • 用不同的Firebase项目try 了不同的应用程序(它们在模拟器上都失败了,但在真实设备上可以工作)
  • try 了Flutterfire CLI和手动配置
  • 创建了具有各种硬件配置文件和Android版本(Play、Non Play、各种API级别)的各种模拟器
  • 已确保在Firebase中启用"匿名登录"
  • 将FiRestore规则设置为Allow Everything If request.auth != null
  • 已判断Windows中的网络设置以允许模拟器访问互联网,但模拟器与所有其他应用程序工作正常
  • try 打开/关闭防火墙并允许完全访问adb.exe(&A)
  • 已将仿真器设置更改为良好信号、完全网络、充电、已插入等.
  • android:usesCleartextTraffic="true"个添加到Android list

请记住,物理设备从一开始就工作得很好,而我不必做很多事情.但在阅读了Stack Overflow几天后,我不知所措.

如果任何人有任何我没有try 过的 idea ,请务必让我知道:) 谢谢.

推荐答案

我也有同样的问题. firebase 基地组件的工作有很大的延迟.我不得不安装较早的仿真器版本.这个问题只出现在我的旧笔记本电脑上,我的电脑没有受到影响.

https://developer.android.com/studio/emulator_archive

Flutter相关问答推荐

如何在Flutter 屏幕中添加箭头形状

为什么他们实例化类,然后丢弃该实例?

相同的Flutter 代码库,但Firebase登录适用于Web应用程序,但无法登录iOS应用程序

如何知道当前屏幕是否处于抖动状态?

Flutter Android Google Sign-in error:ApiException:10在确认软件包名称、SHA-1 fingerprint 和设置同意页面后出现异常

不要跨同步间隔使用BuildContext

Flutter为什么不;没有ListView.iterable()构造函数?

Flutter中不使用Container是否可以做margin

2023 年如何使用 youtube_explode_dart 包下载 URL?

如何将取消图标放置在右上角

我怎样才能消除我的 Column 子元素之间的差距?

如何在 Flutter 中的 BackdropFilter.blur 中制作一个 100x100 的清晰孔

如何在 GridView.builder 中设置 textform 字段并在 flutter 中将 12 个 textformfield 作为单个字符串获取?

Flutter sliver 持久化

如何将金钱格式化为数以百万计的Flutter 动?

无效的 depfile: C:\xxx\xxx\Flutter\project_name\.dart_tool\flutter_build\df4b308df1ee4bce22c56c71751554d1\kernel_snapshot.d 无效

Flutter 中出现错误空判断运算符用于空值

有什么方法可以将 ChangeNotifier 与 ValueListenableBuilder 一起使用

Flutter 中父容器顶部的 Gridview 间距额外区域

在Flutter 中将数字转换为印度文字样式