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 (...) }
versusapply plugin: '...'
, same error result - older versions of lint dependencies
- removing
lintCheck
, or removingtasks.whenTaskAdded
, or downgrading to gradle build tools4.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?