接入Firebase后Android Studio应用运行时Gradle任务执行失败
解决Firebase接入后
mapDebugSourceSetPaths任务执行失败问题 问题核心报错
执行项目时触发以下关键错误:
Execution failed for task ':app:mapDebugSourceSetPaths'. > Error while evaluating property 'extraGeneratedResDir' of task ':app:mapDebugSourceSetPaths' > Failed to calculate the value of task ':app:mapDebugSourceSetPaths' property 'extraGeneratedResDir'. > Querying the mapped value of provider(java.util.Set) before task ':app:processDebugGoogleServices' has completed is not supported
本质是Gradle任务依赖顺序异常,mapDebugSourceSetPaths尝试在processDebugGoogleServices任务完成前读取其生成的资源目录,导致冲突。
解决方案
1. 升级Google Services插件版本
在项目根目录的build.gradle中,将Google Services插件升级到最新稳定版,确保与当前Gradle、AGP版本兼容:
buildscript { dependencies { classpath 'com.google.gms:google-services:4.4.1' // 替换为最新稳定版本 } }
2. 匹配Gradle与AGP版本
检查Gradle和Android Gradle Plugin(AGP)版本是否兼容,常见匹配关系:
- Gradle 8.x → AGP 8.x系列
- Gradle 7.x → AGP 7.x系列
可在gradle/wrapper/gradle-wrapper.properties调整Gradle版本,在app模块build.gradle调整AGP版本。
3. 调整插件应用顺序
在app模块的build.gradle中,必须先应用Android插件,再应用Google Services插件,避免任务依赖逻辑混乱:
plugins { id 'com.android.application' id 'com.google.gms.google-services' // 此插件必须放在Android插件之后 }
4. 清理缓存并重新构建
通过以下方式清除旧缓存,解决缓存导致的任务冲突:
- 打开Android Studio,依次点击
File > Invalidate Caches... > Invalidate and Restart - 或在终端执行命令:
./gradlew clean ./gradlew assembleDebug
5. 验证google-services.json文件
确保google-services.json正确放置在app/模块根目录,且是从Firebase控制台下载的对应项目最新配置文件,文件缺失或位置错误会导致processDebugGoogleServices任务执行异常。
内容的提问来源于stack exchange,提问作者Karl Green
相关产品推荐
相关产品推荐

