You need to enable JavaScript to run this app. 首次运行Flutter Firebase项目出现:app模块build.gradle评估错误
优惠活动
大模型
产品
解决方案
定价
更多

首次运行Flutter Firebase项目出现:app模块build.gradle评估错误

错误原因

该报错是因为android/app/build.gradle配置存在多处语法/位置错误,导致Gradle无法正确解析android配置块,触发方法签名匹配失败异常,具体修复方案如下:

  • 移除defaultConfig块内的错误配置
    你在defaultConfig中错误写入了classpath 'com.android.tools.build:gradle:4.2.0',classpath属于项目级配置,不能放在app级的defaultConfig块中,直接删除该行即可。修改后的defaultConfig块参考:
defaultConfig {
    // TODO: Specify your own unique Application ID.
    applicationId "com.example.firebase_application"
    minSdkVersion 23
    targetSdkVersion 30
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    multiDexEnabled true
}
  • 移除dependencies块内的错误配置
    app级build.gradle的dependencies块中不允许声明classpath,直接删除classpath 'com.google.gms:google-services:4.2.0'这一行,该配置需要放到项目根目录的android/build.gradle文件的dependencies块中。

  • 清理重复和废弃配置

  1. 删除重复的firebase bom声明,保留版本更高的implementation platform('com.google.firebase:firebase-bom:28.3.0')即可,删除26.3.0版本的bom引入行。
  2. 废弃的compile关键字已经淘汰,直接删除compile 'com.android.support:multidex:2.0.1'行即可,你的minSdkVersion已经设置为23,原生支持multidex,无需额外引入依赖。
    修改后的dependencies块参考:
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation platform('com.google.firebase:firebase-bom:28.3.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-messaging'

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
  • 补充根目录build.gradle配置
    打开项目根目录下的android/build.gradle,在dependencies块中补充以下配置:
dependencies {
    classpath 'com.android.tools.build:gradle:4.2.0'
    classpath 'com.google.gms:google-services:4.3.13'
}
  • 同步Gradle配置后重新运行项目即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.10 08:54:02