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

Flutter集成Firebase后Gradle构建失败::app:mapDebugSourceSetPaths任务报错

解决Flutter接入Firebase后出现的:app:mapDebugSourceSetPaths构建错误

针对你遇到的构建错误,这里有几个经过验证的解决办法:

1. 调整Google Services插件的应用顺序

这个错误大多是插件加载顺序导致的任务依赖异常。确保com.google.gms.google-services插件是最后一个被应用的:

  • 打开安卓app模块下的build.gradle文件(路径:android/app/build.gradle)
  • 将apply plugin: 'com.google.gms.google-services'移到文件最末尾,放在所有其他apply plugin语句之后,示例:
    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'dev.flutter.flutter-gradle-plugin'
    
    // 其他配置...
    
    // 确保这行在文件最后
    apply plugin: 'com.google.gms.google-services'
    

2. 手动声明任务依赖关系

如果调整顺序无效,直接指定mapDebugSourceSetPaths任务必须在processDebugGoogleServices完成后执行:
在app模块的build.gradle中添加以下代码:

tasks.named('mapDebugSourceSetPaths') {
    dependsOn('processDebugGoogleServices')
}

// 若release构建也出现相同问题,添加下面这段
tasks.named('mapReleaseSourceSetPaths') {
    dependsOn('processReleaseGoogleServices')
}

3. 清理构建缓存并重新同步

缓存异常也可能引发这类问题,执行以下操作彻底清理:

  • 执行终端命令:
    flutter clean
    cd android && ./gradlew clean
    cd .. && flutter pub get
    
  • 或者在Android Studio中点击File -> Invalidate Caches... -> Invalidate and Restart

错误原因说明

这个问题的核心是Gradle任务的依赖顺序冲突:mapDebugSourceSetPaths需要访问processDebugGoogleServices生成的资源目录,但前者在后者完成前就开始执行了。通过调整插件顺序或手动指定依赖,可以让Gradle正确处理任务执行顺序。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 16:44:57