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.
It seems the issue is the combination of Android Studio 4.1.0 + build gradle tools 4.1.0 + lintCheck()
+ tasks.whenTaskAdded {}
.
lintrules/build.xml
, e.g. maven-publish
, org.jetbrains.kotlin.jvm
, same error resultplugins { id (...) }
versus apply plugin: '...'
, same error resultlintCheck
, or removing tasks.whenTaskAdded
, or downgrading to gradle build tools 4.0.1
, any of these makes it work againAnyone else having the same problem?
Just delete gradle folder , and let android studio download it again with click on Sync now !. Save this answer.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With