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

无法从命令行构建Android项目的问题求助

问题

在CentOS机器上按照Android官方文档从命令行构建Android项目,已安装Android SDK和JDK 21,执行./gradlew task-name类Gradle任务时出现如下报错:

> Task :tasks FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':tasks'.
> Could not create task ':app:compileBlackBox32DebugAndroidTestKotlin'.
   > Cannot use @TaskAction annotation on method AbstractKotlinCompile.execute() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.

* Try:
> Run with --stacktrace option to get the stack trace.
> 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.

Deprecated 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.

BUILD FAILED in 896ms
1 actionable task: 1 executed

更换JDK版本为17后仍出现相同错误,求问题原因及解决方法。

原因分析

核心问题是Kotlin Gradle插件版本与当前使用的Gradle版本不兼容。旧版本的Kotlin插件仍将IncrementalTaskInputs作为@TaskAction方法的参数,但该参数类型在Gradle 7.0及以上版本已被废弃,高版本Gradle不再支持这种用法,直接导致任务创建失败。

解决方法
  • 升级Kotlin Gradle插件版本:在项目根目录的build.gradle(或build.gradle.kts)文件中,将Kotlin插件版本更新到与当前Gradle版本匹配的兼容版本。例如使用Gradle 8.5时,建议升级到Kotlin插件1.9.20及以上版本。修改示例:
    buildscript {
        ext.kotlin_version = "1.9.20"
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
  • 校验AGP、Gradle、Kotlin版本兼容性:如果项目使用Android Gradle Plugin(AGP),需确保AGP版本、Gradle版本、Kotlin插件版本三者相互匹配。比如AGP 8.2.x对应Gradle 8.2+、Kotlin插件1.9.x。
  • 清理缓存后重新构建:修改配置后,执行./gradlew clean清理旧构建缓存,再重新运行目标任务。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 06:32:12