6

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?

gdrehmer
  • 136
  • 5
  • Someone pointed me towards https://issuetracker.google.com/issues/170656529 The way to by pass this is to test by `System.getProperty("idea.active") != "true"` and bypass lint checks for the IDE only – gdrehmer Nov 06 '20 at 05:42

1 Answers1

2

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)

gdrehmer
  • 136
  • 5