【错误记录】Android Studio 编译报错 ( Could not create task ‘:app:processDebugResources‘. Cannot use @TaskAc )_could not create task \':app:processdebugresources\'
文章目录
- 一、报错信息
-
- 1、核心报错
- 2、完整报错
- 二、解决方案
-
- 1、问题分析
- 2、完整代码
总结 :
Gradle 版本 与 AGP ( Android Gradle Plugin ) 插件版本 不匹配 ;
Gradle 8.5 对应的 Android Gradle 插件 (AGP) 版本建议为 8.1.0 及以上 ;
设置 AGP 插件版本为 8.1.0 ;
一、报错信息
1、核心报错
核心报错信息 :
Could not create task \':app:processDebugResources\'.Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
2、完整报错
完整报错信息 : 仅做参考 , 不要展开代码 ;
Could not create task \':app:processDebugResources\'.Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.* Try:> Run with --info or --debug option to get more log output.> Run with --scan to get full insights.> Get more help at https://help.gradle.org.* Exception is:com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not create task \':app:processDebugResources\'.Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.executeAction(GradleModelFetchAction.java:255)at com.intellij.gradle.toolingExtension.impl.modelAction.GradleModelFetchAction.doExecute(GradleModelFetchAction.java:144) 省略 100 行at org.gradle.api.internal.DefaultNamedDomainObjectCollection$AbstractDomainObjectCreatingProvider.tryCreate(DefaultNamedDomainObjectCollection.java:947)... 215 moreDeprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.You can use \'--warning-mode all\' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.BUILD FAILED in 1s
二、解决方案
1、问题分析
报错 :
Could not create task \':app:processDebugResources\'.Cannot use @TaskAction annotation on method IncrementalTask.taskAction$gradle_core() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
Android Studio 报错 Could not create task \':app:processDebugResources\'
以及关于 @TaskAction 注解的问题 , 这种类型的报错 通常是由 Gradle 版本 与项目配置不兼容导致的 ;
Gradle 版本 与 AGP ( Android Gradle Plugin ) 插件版本 不匹配 ;
这种错误之前已经遇到很多次了 ;
Gradle 8.5 对应的 Android Gradle 插件 (AGP) 版本建议为 8.1.0 及以上 ;
设置 AGP 插件版本为 8.1.0 ;
在项目根目录的 build.gradle 文件中 , 应使用以下配置配置 AGP 版本 :
buildscript { repositories { google() mavenCentral() } dependencies { // 使用兼容 Gradle 8.5 的 AGP 版本 classpath \'com.android.tools.build:gradle:8.1.0\' }}
设置 Gradle 版本号 :
#Mon Jun 16 12:52:35 CST 2025distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distsdistributionUrl=https\\://services.gradle.org/distributions/gradle-8.5-bin.zipzipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/dists
2、完整代码
项目根目录的 build.gradle 文件 :
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { ext { agp_version = \'8.1.0\' } repositories { mavenCentral() maven { url \'https://jitpack.io\' } google() //jcenter() } dependencies { classpath \"com.android.tools.build:gradle:$agp_version\" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files }}allprojects { repositories { mavenCentral() maven { url \'https://jitpack.io\' } google() //jcenter() }}task clean(type: Delete) { delete rootProject.buildDir}