无法创建任务“:app:compileDebugKotlin”。无法创建任务“:app:dataBindingGenBaseClassesDebug”。

10
我在构建应用程序时遇到了错误。
> Could not create task ':app:compileDebugKotlin'.
> Could not create task ':app:dataBindingGenBaseClassesDebug'.
> Cannot use @TaskAction annotation on method DataBindingGenBaseClassesTask.writeBaseClasses() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
4个回答

8
在从7.x升级到8.x时构建项目时,我遇到了以下错误:
Cannot use @TaskAction annotation on method DataBindingGenBaseClassesTask.writeBaseClasses() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.

由于接受的答案中没有降级选项,我不得不按照以下步骤进行操作。我使用的是 Android Studio chipmunk 版本,它可以让我选择最新的 Gradle 版本,但无法选择 Android Gradle 插件和 Kotlin Gragle 插件。

  • 如果您使用的是 AGP 7.2+,请使用 ./gradlew -Pandroid.debug.obsoleteApi=true 命令获取在 8 中可能失败的 API 的重要警告。

  • 升级 Android Studio,这将使您可以访问最新的 AGP 和 KGP。我升级到了 Eel 2022.1.1 版本。如果您尝试在旧版 Android Studio 中将 Kotlin Gradle 插件升级到最新版本,则会收到以下提示:

Kotlin version that is used for building with Gradle differs from the one bundled into the IDE

  • 将compileOptions和kotlinOptions设置为Java 11。低于11的版本不被接受。

  • 更新kotlin-gradle-plugin。

  • 如果正在使用,请删除kotlin-android-extensions插件。

  • 添加kotlin-parcelize插件以访问Parcelize类。

  • 将kotlinx.android.parcel更改为kotlinx.parcelize。

  • 删除jcenter。

  • 用以下代码替换已弃用的onBackPressed():

     onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
         override fun handleOnBackPressed() {
             // your code
         }
     })
    
  • 升级依赖库中的库。在构建时,Retrofit库会出现问题。

终于我成功构建了这个项目。以下是各个版本:

enter image description here

此外,这些步骤帮助我解决了问题,你的情况可能会有所不同。


更新 Kotlin Gradle 插件,问题已经解决,谢谢。 - Carl Cheung
为什么更改Android Gradle插件需要我们同时更改Kotlin Gradle插件呢? - Nitin Sethi

4

React Native 0.72.0 + Amplitude

我在将Amplitude添加到React Native项目后遇到了这个错误。

package.json:

{
  ...
  dependencies: {
    "react-native": "^0.72.0",
    "@amplitude/analytics-react-native": "^1.3.3",
    ...
  }
}

为了修复这个问题,我在根目录的build.gradle文件中添加了kotlinVersion = "1.8.22"。

<project_root>/android/build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33

        // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
        ndkVersion = "23.1.7779620"
        // required by Amplitude, overrides version included by library
        kotlinVersion = "1.8.22" // <-- add this line
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
    }
}


3

当我在“项目结构”->“项目”中将Gradle版本设置为8.0里程碑版5时,我遇到了相同的错误。将其更改为7.6版本可以解决此问题。


0
我进行了两个更改和我的项目工作。
第一个是在build.gradle中进行的更改。
  classpath 'com.android.tools.build:gradle:8.x.x'

  classpath 'com.android.tools.build:gradle:7.x.x'

从你的旧项目中,你可以检查你的类路径版本。
第二个。
在gradle-wrapper.properties文件中进行更改。
distributionUrl=https://services.gradle.org/distributions/gradle-8.x.zip

distributionUrl=https\://services.gradle.org/distributions/gradle-7.x.x.zip

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接