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

Flutter构建失败::app:mapDebugSourceSetPaths任务执行异常求助

解决Flutter升级AGP与SDK版本后mapDebugSourceSetPaths构建失败问题

核心原因分析

该错误源于Google Services插件与AGP 7.4的任务执行顺序冲突:mapDebugSourceSetPaths任务会提前查询processDebugGoogleServices生成的映射文件,但后者尚未完成执行。降级google-services到4.3.15无效,是因为该版本未完全适配AGP 7.4的任务依赖逻辑。

分步解决方案

1. 升级Google Services插件至适配版本

将项目根目录build.gradle中的google-services版本更新到4.4.0及以上(该版本专门修复了AGP 7.x的任务顺序问题):

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.4.1' // 推荐使用最新稳定版
    }
}

2. 强制任务执行顺序

在android/app/build.gradle中,为mapDebugSourceSetPaths任务添加对processDebugGoogleServices的显式依赖,确保任务执行顺序正确:

afterEvaluate {
    tasks.named('mapDebugSourceSetPaths') {
        dependsOn 'processDebugGoogleServices'
    }
    // 若release构建也出现相同问题,添加对应任务依赖
    tasks.named('mapReleaseSourceSetPaths') {
        dependsOn 'processReleaseGoogleServices'
    }
}

3. 验证Flutter Gradle插件兼容性

确保Flutter Gradle插件与AGP 7.4兼容,在android/settings.gradle中检查插件版本:

plugins {
    id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false // Flutter 3.10+推荐此版本,需匹配你的Flutter版本
}

若你的Flutter版本低于3.10,建议升级到最新稳定版,该版本对AGP 7.4的支持更完善。

4. 清理构建缓存

执行以下命令清理缓存,避免旧缓存引发的冲突:

flutter clean
rm -rf android/.gradle
flutter pub get
flutter run

额外排查点

  • 确认android/app/google-services.json为最新版本,与Firebase/Google服务配置匹配。
  • 检查所有第三方依赖(如Firebase相关库)已升级至适配SDK 33/34的版本,避免版本不匹配引发连锁问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 10:45:56