androidgradlelintandroid-studio-4.1

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

Question

Anyone else having the same problem?


Solution

  • 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)