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

Flutter集成Firebase报错:未找到匹配包名的客户端

Flutter集成Firebase报错:No matching client found for package name

运行集成Firebase的Flutter应用时遇到以下错误:

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugGoogleServices'.
> No matching client found for package name 'com.example.check'

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 13s
Error: Gradle task assembleDebug failed with exit code 1

已确认android/app/build.gradle中applicationId设置为com.example.check,配置如下:

plugins {
    id "com.android.application"
    // START: FlutterFire Configuration
    id 'com.google.gms.google-services'
    // END: FlutterFire Configuration
    id "kotlin-android"
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id "dev.flutter.flutter-gradle-plugin"
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file("local.properties")
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader("UTF-8") { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty("flutter.versionCode")
if (flutterVersionCode == null) {
    flutterVersionCode = "1"
}

def flutterVersionName = localProperties.getProperty("flutter.versionName")
if (flutterVersionName == null) {
    flutterVersionName = "1.0"
}

android {
    namespace = "com.example.check"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = flutter.ndkVersion

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.check"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 21
        targetSdk = flutter.targetSdkVersion
        versionCode = flutterVersionCode.toInteger()
        versionName = flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.debug
        }
    }
}

flutter {
    source = "../../"
}

已执行的操作:

  • 从Firebase控制台下载google-services.json并放置在android/app目录下;
  • 确认Firebase控制台的包名与build.gradle中的applicationId一致,均为com.example.check;
  • 执行了flutter clean和flutter pub get命令清理并重建项目。

可能的解决方法

  1. 检查google-services.json中的包名
    打开android/app/google-services.json,查找client节点下的package_name字段,确认是否和applicationId完全一致,注意大小写、拼写(比如有没有多余的空格或标点)。

  2. 重新下载google-services.json
    删除现有google-services.json文件,重新从Firebase控制台下载对应应用的配置文件,确保下载时选择的包名正确。

  3. 检查gradle插件版本兼容性
    确认项目根目录build.gradle中com.google.gms.google-services插件版本和Firebase依赖版本匹配,建议使用最新兼容版本。

  4. 检查多环境配置
    如果项目中有productFlavors或不同buildTypes配置了不同的applicationId,需要确保Firebase控制台添加了对应环境的包名,且google-services.json包含对应client节点配置。

  5. 清理gradle缓存
    执行以下命令清理gradle缓存:

    ./gradlew cleanBuildCache
    

    之后重新运行flutter run。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 06:36:01