tankistorep
06/02/2023, 9:00 AMnowinandroid
app has done. But I keep getting this error any time I change any code in the plugins module, or if I do a clean build:
Cause: loader constraint violation in interface itable initialization for class com.android.build.gradle.internal.api.VariantFilter
Strangely, what makes it temporarily go away is doing a build with --scan, but I have no idea what causes it, especially because I’m not using variant filters. More details about the error + setup in thread.tankistorep
06/02/2023, 9:01 AMenum class Flavor(val id: String) {
Foo("foo"),
Bar("bar"),
Foobar("foobar"),
;
}
internal fun configureFlavors(
commonExtension: CommonExtension<*, *, *, *>,
flavorConfigurationBlock: ProductFlavor.(flavor: Flavor) -> Unit = {}
) {
val myDimension = "environment"
commonExtension.apply {
flavorDimensions.add(myDimension)
productFlavors {
Flavor.values().forEach { flavor ->
create(flavor.id) {
dimension = myDimension
flavorConfigurationBlock(this, flavor)
if (this@apply is ApplicationExtension && this is ApplicationProductFlavor) {
applicationIdSuffix = ".${flavor.id}"
}
}
}
}
}
}
Again, this is pretty much following exactly the nowinadroid
app. This is called from the Application and Library convention plugin codetankistorep
06/02/2023, 9:01 AMloader constraint violation in interface itable initialization for class com.android.build.gradle.internal.api.VariantFilter: when selecting method 'com.android.builder.model.BuildType com.android.build.api.variant.VariantFilter.getBuildType()' the class loader org.gradle.internal.classloader.VisitableURLClassLoader @d504be for super interface com.android.build.api.variant.VariantFilter, and the class loader org.gradle.internal.classloader.VisitableURLClassLoader @6ee373d4 of the selected method's class, com.android.build.gradle.internal.api.VariantFilter have different Class objects for the type com.android.builder.model.BuildType used in the signature (com.android.build.api.variant.VariantFilter is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @d504be, parent loader org.gradle.internal.classloader.CachingClassLoader @28f524f8; com.android.build.gradle.internal.api.VariantFilter is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader @6ee373d4, parent loader org.gradle.internal.classloader.VisitableURLClassLoader @d504be)
alex.krupa
06/27/2023, 12:47 PM./gradlew --stop
.alex.krupa
06/27/2023, 12:48 PMtankistorep
06/27/2023, 1:26 PMbuildSrc
module and an included build module (build-logic
). I moved everything to be just in build-logic
and haven’t seen the error since. Again, I’m not sure why this was causing an error (maybe some race condition?), and I’m not sure if it applies to you, but that’s what fixed it for me.alex.krupa
06/27/2023, 1:43 PMalex.krupa
06/27/2023, 1:44 PMbuildSrc
with convention plugins, we haven't moved everything because buildSrc
just has some constants and minor utilities — haven't considered that this might be the culprittankistorep
06/27/2023, 2:10 PMbuildSrc
had a couple of util classes. Glad I could help, if anyone figures out the actual root cause, please do share!Balázs Varga
08/04/2024, 6:44 PMimplementation('com.android.tools.build:gradle')
to implementation('com.android.tools.build:gradle-api')
in `buildSrc`’s build.gradle
. Interestingly, the problem only manifested in Kotlin DSL modules, while everything worked fine with Groovy.
I found two potential solutions:
1. Roll back to using com.android.tools.build:gradle
in buildSrc
.
2. Add the following to the root build.gradle
(previously omitted due to our use of version catalogs):
plugins {
alias(libs.plugins.androidLibrary) apply false
}
I hope this helps someone facing similar issues!