Could not create task ':app:compileDebugKotlin'

I have been developing an android app using Kotlin in Android studio.

Here is my error when trying to sync gradle files:

A build operation failed.
    Could not create task ':app:compileDebugKotlin'.
Could not create task ':app:compileDebugKotlin'.
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.

./gradlew build --stacktrace > logs.txt 2>logErrors.txt

Log errors:

[Log errors - Pastebin.com]

app/build.gradle.kts

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
}

android {
    namespace = "com.example.wherehouse"
    compileSdk = 33

    defaultConfig {
        applicationId = "com.example.wherehouse"
        minSdk = 24
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "11"
    }
}

dependencies {
    implementation("androidx.core:core-ktx:1.9.0")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.9.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("com.journeyapps:zxing-android-embedded:4.2.0")
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
    implementation("org.jetbrains.kotlin:kotlin-stdlib:1.5.21")
}

root/build.gradle.kts

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

buildscript {
    val agp_version by extra("7.4.2")
    val agp_version1 by extra("8.0.0")
    val agp_version2 by extra("8.1.3")
    val agp_version3 by extra(agp_version2)

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
        classpath("com.android.tools.build:gradle:$agp_version2")
    }
}

Gradle plugin version and Gradle version

Attempted solutions:
invalidating caches, restarting, project rebuilding etc…

Updating gradle version, downgrading gradle version
updating java jdk, downgrading java jdk

altering compileOptions do different java versions.

I end up in a circle, coming back to the same problem after trying to fix new ones.

You have two significant problems.

The

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.

you showed in text here is because you use Kotlin Gradle Plugin 1.5.12 which is not compatible with Gradle 8+.

The error in the log on pastebin is totally unrelated, it says that you use an Android Gradle Plugin version that requires that you run Gradle itself with at least Java 11, but you use Java 8 to run Gradle.

Hi, Thanks for the response. I was able to fix this by altering my Java version to 11 and using AGP android upgrade assistant
using these dependencies:

    dependencies {
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21")
        // https://mvnrepository.com/artifact/com.android.tools.build/gradle
        classpath("com.android.tools.build:gradle:8.1.0")

    }

These plugin versions:
image_2023-11-15_141744055

and this in gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip

Then I went to Tools > AGP Upgrade Assistant and pressed run, then it sorted itself out!
Docs for this tool
So take my versions with a pinch of salt.

1 Like