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

Flutter连接Firebase失败求助:Linux环境VSCode运行报错

Flutter Linux 环境下 Firebase 连接失败(Channel Error)解决方案

报错信息

Launching lib/main.dart on Linux in debug mode...
main.dart:1
Connecting to VM Service at ws://127.0.0.1:42365/Ry6K9giFyvk=/ws
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
#0      FirebaseCoreHostApi.initializeCore
messages.pigeon.dart:210
<asynchronous suspension>
#1      MethodChannelFirebase._initializeCore
method_channel_firebase.dart:29
<asynchronous suspension>
#2      MethodChannelFirebase.initializeApp
method_channel_firebase.dart:73
<asynchronous suspension>
#3      Firebase.initializeApp
firebase.dart:43
<asynchronous suspension>

修复步骤

  • 安装Linux系统依赖
    Firebase Core在Linux上需要特定系统库,执行以下命令安装:

    sudo apt-get install libsecret-1-dev libsqlite3-dev
    
  • 验证配置文件位置与引用
    将google-services.json放置在项目的linux/目录下,同时修改linux/CMakeLists.txt,添加配置文件复制逻辑:

    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/google-services.json ${CMAKE_CURRENT_BINARY_DIR}/google-services.json COPYONLY)
    
  • 更新依赖并清理项目
    打开pubspec.yaml,确保firebase_core等Firebase插件使用最新稳定版本,然后执行:

    flutter pub get
    flutter clean
    flutter run
    
  • 检查Flutter Linux环境完整性
    运行flutter doctor,修复所有提示的Linux开发环境问题,比如缺失的工具链或依赖包。

  • 重新配置Firebase项目
    如果上述方法无效,重新执行Firebase配置命令,确保选择正确的项目和Linux平台:

    flutterfire configure
    

内容的提问来源于stack exchange,提问作者Susan Varghese Padath

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 11:27:16