Android Studio修改target SDK至33后报错的解决方法咨询
解决 targetSdkVersion 33 下的 Gradle 任务执行错误
翻译后的错误内容
任务 ':app:mapDebugSourceSetPaths' 执行失败。 > 评估任务 ':app:mapDebugSourceSetPaths' 的 'extraGeneratedResDir' 属性时出错 > 无法计算任务 ':app:mapDebugSourceSetPaths' 的 'extraGeneratedResDir' 属性值。 > 不支持在任务 ':app:processDebugGoogleServices' 完成前查询 provider(java.util.Set) 的映射值 * 尝试: > 使用 --info 或 --debug 选项运行以获取更多日志输出。 > 使用 --scan 运行以获取完整分析信息。 * 异常信息: org.gradle.api.tasks.TaskExecutionException: 任务 ':app:mapDebugSourceSetPaths' 执行失败。 at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:38)
可行解决步骤
- 更新Google Services插件版本:在项目根目录的
build.gradle文件中,将com.google.gms:google-services插件更新至最新稳定版(如4.4.0及以上),旧版本与targetSdk33的Gradle任务兼容性较差。 - 调整任务依赖关系:在app模块的
build.gradle中添加任务依赖,确保mapDebugSourceSetPaths在processDebugGoogleServices完成后执行:tasks.named('mapDebugSourceSetPaths') { mustRunAfter 'processDebugGoogleServices' } tasks.named('mapReleaseSourceSetPaths') { mustRunAfter 'processReleaseGoogleServices' } - 清理Gradle缓存:执行以下命令清除缓存后重新构建:
./gradlew clean build --refresh-dependencies - 检查Android Gradle插件版本:确保项目使用的Android Gradle插件(AGP)版本与targetSdk33兼容,比如AGP 7.4.0及以上版本对targetSdk33支持更完善,在根目录
build.gradle中更新:dependencies { classpath 'com.android.tools.build:gradle:7.4.2' }
内容的提问来源于stack exchange,提问作者lizi zaridze
相关产品推荐
相关产品推荐

