Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build tools 4.1.0 failing sync in Android Studio when there is a lintCheck dependency

We have an Android multi module project with custom lint checks and we've been trying to move to Android gradle build tools 4.1.0, but Android Studio 4.1.0 gradle sync keeps failing.

Say we have two modules (plus some irrelevant "library" modules):

  • app (main app module)
  • lintchecks (custom lint rules)

app uses the custom lintchecks module, in app/build.gradle:

  lintChecks project(":lintchecks")

Now, say there is some custom plugin (e.g. in buildSrc) or configuration using the combination of subprojects and tasks.whenTaskAdded. For example, in ./build.gradle:

subprojects {
   tasks.whenTaskAdded { 
     // content not important
   }
}

There's nothing special in the lintcheck configuration. For example in lintchecks/build.gradle:

apply plugin: 'kotlin'

dependencies {
    compileOnly "com.android.tools.lint:lint-api:27.1.0"
    compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation "com.android.tools.lint:lint:27.1.0"
    testImplementation "com.android.tools.lint:lint-tests:27.1.0"
    testImplementation "com.android.tools:testutils:27.1.0"
}

jar {
    manifest {
        attributes("Lint-Registry-v2": "com.company.lintrules.IssueRegistry")
    }
}

It has been failing all the time on Android Studio sync with error similar to:

A problem occurred evaluating project ':lintrules'.
> Failed to apply plugin 'kotlin'.
   > Gradle#projectsEvaluated(Action) on build 'MyCompanyBuild' cannot be executed in the current context.

In Summary

It seems the issue is the combination of Android Studio 4.1.0 + build gradle tools 4.1.0 + lintCheck() + tasks.whenTaskAdded {}.

What I've tried

  • different plugins in lintrules/build.xml, e.g. maven-publish, org.jetbrains.kotlin.jvm, same error result
  • different way to declare the plugin, e.g. plugins { id (...) } versus apply plugin: '...', same error result
  • older versions of lint dependencies
  • removing lintCheck, or removing tasks.whenTaskAdded, or downgrading to gradle build tools 4.0.1, any of these makes it work again
  • running any command on terminal, outside of Android Studio, it works fine, issue seems to be only on the A.S. sync operation.

Question

Anyone else having the same problem?

like image 687
gdrehmer Avatar asked Oct 28 '20 23:10

gdrehmer


People also ask

How do I fix Gradle's dependency cache may be corrupt?

Just delete gradle folder , and let android studio download it again with click on Sync now !. Save this answer.


1 Answers

This problem is being reported under ticket https://issuetracker.google.com/issues/170656529

The way to workaround this for now is to skip the logic causing issues on the IDE testing for idea.active system property:

if(System.getProperty("idea.active") != "true"){
  tasks.whenTaskAdded {
    (...)
  }
}

(Thanks Jerry for finding the ticket)

like image 111
gdrehmer Avatar answered Oct 18 '22 13:10

gdrehmer