After updating Android Studio to the latest Android Studio Ladybug | 2024.2.1 and Gradle plugin to 8.6.0, I am getting these compile-time errors and am unable to create a build.
A problem occurred evaluating root project 'AndApp'. A problem occurred configuring project ':app'. com.android.build.gradle.internal.crash.ExternalApiUsageException: org.gradle.api.UnknownTaskException: Task with name 'lintDebug' not found in project ':app'.
build.gradle code here
android {
compileSdk 35
buildToolsVersion = '35.0.0'
ndkVersion "26.2.11394342"
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of("17"))
}
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17
}
defaultConfig {
applicationId "com.test"
minSdkVersion 24
targetSdkVersion 35
}
applicationVariants.configureEach {
def variantName = name.capitalize()
def lintTask = tasks.named("lint${variantName}")
assembleProvider.get().dependsOn.add(lintTask)
}
}
ExternalApiUsageException error in the latest gradle update (8.6.0).
Task with name 'lintDebug' not found in the project ':app'.
Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'AndApp'."
Caused by: java.lang.RuntimeException: com.android.build.gradle.internal.crash.ExternalApiUsageException: org.gradle.api.UnknownTaskException: Task with name 'lintDebug' not found in project ':app'. at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:71) at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:54)`
Can someone please help me resolve these issues ?
Code where it's got an error
applicationVariants.configureEach {
def variantName = name.capitalize()
def lintTask = tasks.named("lint${variantName}") // error line
assembleProvider.get().dependsOn.add(lintTask)
}
Instead of directly referencing the lint tasks by their name, you can retrieve all lint tasks dynamically with tasks.withType and then configure dependencies.
Try updating your applicationVariants.configureEach block as below:
applicationVariants.configureEach { variant ->
def lintTaskName = "lint${variant.name.capitalize()}"
tasks.matching { it.name == lintTaskName }.configureEach { lintTask ->
assembleProvider.get().dependsOn(lintTask)
}
}
If the above solution doesn't work then try this.
applicationVariants.configureEach { variant ->
def lintTask = tasks.findByName("lint${variant.name.capitalize()}")
if (lintTask != null) {
assembleProvider.get().dependsOn(lintTask)
}
}