克隆Flutter项目后无法访问Firebase/Firestore,需如何配置?
克隆集成Firebase的Flutter应用后恢复访问权限的必要配置
错误信息翻译:
D/EGL_emulation(10634): app_time_stats: 平均值=6275.84ms 最小值=9.86ms 最大值=106419.61ms 次数=17 D/EGL_emulation(10634): app_time_stats: 平均值=11.48ms 最小值=5.31ms 最大值=40.71ms 次数=60 D/EGL_emulation(10634): app_time_stats: 平均值=9.29ms 最小值=4.92ms 最大值=16.29ms 次数=56 D/EGL_emulation(10634): app_time_stats: 平均值=8.66ms 最小值=5.06ms 最大值=15.26ms 次数=61 D/EGL_emulation(10634): app_time_stats: 平均值=9.94ms 最小值=4.58ms 最大值=24.23ms 次数=61 D/EGL_emulation(10634): app_time_stats: 平均值=10.22ms 最小值=5.13ms 最大值=20.02ms 次数=60 D/EGL_emulation(10634): app_time_stats: 平均值=8.59ms 最小值=4.91ms 最大值=15.28ms 次数=60 D/EGL_emulation(10634): app_time_stats: 平均值=8.31ms 最小值=5.03ms 最大值=16.29ms 次数=61 D/EGL_emulation(10634): app_time_stats: 平均值=8.91ms 最小值=4.52ms 最大值=14.01ms 次数=61 D/EGL_emulation(10634): app_time_stats: 平均值=9.90ms 最小值=4.90ms 最大值=17.99ms 次数=60 I/flutter (10634): 2 false D/EGL_emulation(10634): app_time_stats: 平均值=9.15ms 最小值=5.06ms 最大值=22.87ms 次数=60 D/EGL_emulation(10634): app_time_stats: 平均值=83.28ms 最小值=12.88ms 最大值=1016.12ms 次数=15 W/Firestore(10634): (24.4.0) [WatchStream]: (24ebbad) 流已关闭,状态:Status{code=UNAVAILABLE, description=调用了Channel shutdownNow, cause=null}。 W/DynamiteModule(10634): 未找到com.google.android.gms.providerinstaller.dynamite的本地模块描述符类。 I/DynamiteModule(10634): 正在考虑本地模块com.google.android.gms.providerinstaller.dynamite:0和远程模块com.google.android.gms.providerinstaller.dynamite:0 W/ProviderInstaller(10634): 加载providerinstaller模块失败:未找到可接受的com.google.android.gms.providerinstaller.dynamite模块。本地版本为0,远程版本为0。
解决配置步骤
1. 补全Firebase平台配置文件
- Android:从Firebase控制台下载
google-services.json,放置到项目的android/app目录下 - iOS:从Firebase控制台下载
GoogleService-Info.plist,通过Xcode添加到项目的Runner目录(勾选"Copy items if needed")
2. 验证依赖与插件配置
- 确认
pubspec.yaml中已引入firebase_core、firebase_auth、cloud_firestore等必要依赖,执行flutter pub get拉取依赖 - 检查Android端配置:
- 根目录
build.gradle需包含classpath 'com.google.gms:google-services:4.3.15'(或兼容的最新版本) android/app/build.gradle末尾需添加apply plugin: 'com.google.gms.google-services'
- 根目录
3. 修复Google Play服务问题
针对日志中ProviderInstaller加载失败的问题:
- 使用包含Google Play服务的模拟器镜像(如"Google APIs Intel x86 Atom System Image")
- 确保真机/模拟器已安装最新版Google Play服务
- 执行
flutter clean后重新编译
4. 核对Firebase控制台配置
- 确认控制台中应用的包名(Android)/Bundle ID(iOS)与新项目完全匹配
- 检查Firebase的认证、Firestore服务是否已启用,安全规则未非法限制访问(测试阶段可临时放宽,上线前需严格配置)
5. 清理缓存重建项目
- 执行
flutter clean清除旧构建缓存 - 执行
flutter pub get重新获取依赖 - 重启模拟器/真机后重新运行项目
内容的提问来源于stack exchange,提问作者cueless
相关产品推荐
相关产品推荐

