You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter项目Firebase/Firestore在安卓模拟器无法运行,真机正常

Flutter Firebase/Firestore安卓模拟器无法运行但真机正常问题

问题概述

Flutter项目中Firebase/Firestore无法在安卓模拟器上正常运行,但在Android Go和Android 12的实体设备上可完美工作。当前仅在基础项目中测试匿名登录,通过终端输出验证应用与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]

已尝试的解决方案

  • 验证安卓模拟器网络正常,Chrome、地图等应用可正常访问网络
  • 在主版和调试版AndroidManifest中添加<uses-permission android:name="android.permission.INTERNET"/>和<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />权限
  • 重新安装Windows系统
  • 按照指南重新安装Flutter、Android SDK、Android Studio、VSCode并确保配置正确
  • 设置minSdkVersion 22
  • 尝试不同应用和Firebase项目,均出现模拟器失败、真机正常的情况
  • 尝试Flutterfire CLI配置和手动配置两种方式
  • 创建多种硬件配置、不同Android版本(带Play/不带Play、不同API级别)的模拟器
  • 确保Firebase中已启用匿名登录
  • 设置Firestore规则,当request.auth != null时允许所有操作
  • 检查Windows网络设置,确保模拟器可访问网络(其他应用正常)
  • 尝试开启/关闭防火墙,并允许adb.exe完全访问
  • 修改模拟器设置为良好信号、满格网络、充电状态等
  • 在AndroidManifest中添加android:usesCleartextTraffic="true"

经过多日排查仍无头绪,恳请提供未尝试过的解决方案。


内容的提问来源于stack exchange,提问作者marshalbyref

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 14:01:12