升级AGP后项目无法构建,processDebugResources任务创建失败
AGP升级后构建失败:IncrementalTaskInputs参数错误修复
问题重现
升级Android Gradle Plugin(AGP)至最新版本后,项目无法构建,报错:
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.
完整错误日志:
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.
当前配置
模块build.gradle
plugins { id 'com.android.application' } android { compileSdk 34 defaultConfig { applicationId "eu.obsys.staffkeeper" minSdk 30 targetSdk 34 versionCode 59 versionName "Amentet" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' debuggable true } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' debuggable false } } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } buildFeatures { // dataBinding true viewBinding true } namespace 'eu.obsys.staffkeeper' } dependencies { implementation 'androidx.databinding:databinding-runtime:4.0.0' implementation 'androidx.activity:activity:1.9.0' modules { module("org.jetbrains.kotlin:kotlin-stdlib-jdk7") { replacedBy("org.jetbrains.kotlin:kotlin-stdlib", "kotlin-stdlib-jdk7 is now part of kotlin-stdlib") } module("org.jetbrains.kotlin:kotlin-stdlib-jdk8") { replacedBy("org.jetbrains.kotlin:kotlin-stdlib", "kotlin-stdlib-jdk8 is now part of kotlin-stdlib") } } implementation fileTree(dir: 'libs', include: ['*.aar']) implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.11.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.7.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0' implementation 'androidx.navigation:navigation-fragment:2.7.7' implementation 'androidx.navigation:navigation-ui:2.7.7' implementation 'androidx.annotation:annotation:1.7.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'com.android.volley:volley:1.2.1' implementation 'com.google.code.gson:gson:2.10.1' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" implementation 'com.github.yuriy-budiyev:code-scanner:2.1.2' implementation "androidx.core:core:1.13.0" // testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' }
根目录build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() jcenter() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath 'com.android.tools.build:gradle:4.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31" } } task clean(type: Delete) { delete rootProject.buildDir }
修复步骤
1. 同步AGP与Gradle版本
当前根配置中AGP版本仍为4.2.2,与升级操作不符,这是核心冲突源。需将AGP、Gradle、Kotlin插件版本统一为兼容组合(以AGP 8.4.0为例,对应Gradle 8.6+、Kotlin 1.9.22+):
- 修改根目录build.gradle为现代plugins写法:
plugins { id 'com.android.application' version '8.4.0' apply false id 'org.jetbrains.kotlin.android' version '1.9.22' apply false } task clean(type: Delete) { delete rootProject.buildDir }
- 更新
gradle/wrapper/gradle-wrapper.properties中的Gradle版本:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
2. 移除过时的DataBinding依赖
AGP 7.0+会自动管理DataBinding runtime依赖,手动引入的androidx.databinding:databinding-runtime:4.0.0与新版本AGP冲突,直接删除该行:
// 移除这行 // implementation 'androidx.databinding:databinding-runtime:4.0.0'
3. 清理过时的Kotlin配置
旧版本Kotlin的stdlib-jdk7/jdk8模块已合并到标准库中,移除对应的替换配置:
// 删除整个modules块 // modules { // module("org.jetbrains.kotlin:kotlin-stdlib-jdk7") { // replacedBy("org.jetbrains.kotlin:kotlin-stdlib", "kotlin-stdlib-jdk7 is now part of kotlin-stdlib") // } // module("org.jetbrains.kotlin:kotlin-stdlib-jdk8") { // replacedBy("org.jetbrains.kotlin:kotlin-stdlib", "kotlin-stdlib-jdk8 is now part of kotlin-stdlib") // } // }
4. 升级Java版本
AGP 8.x要求最低Java 17,修改模块build.gradle中的编译选项:
compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 }
同时确保Android Studio已配置Java 17 SDK(通过File -> Project Structure -> SDK Location设置)。
5. 清理缓存并重建
完成上述修改后:
- 执行
File -> Invalidate Caches... -> Invalidate and Restart重启Android Studio - 或在终端运行:
./gradlew clean build --refresh-dependencies
内容的提问来源于stack exchange,提问作者Riko
相关产品推荐
相关产品推荐

