I'm getting when applying the Kotlin Multiplatform...
# gradle
c
I'm getting when applying the Kotlin Multiplatform plugin as well as the Android library plugin…
Copy code
Could not create an instance of type org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget.
> Could not generate a decorated class for type KotlinAndroidTarget.
   > com/android/build/gradle/api/BaseVariant
The error message doesn't help me at all, where should I look for to fix this?
m
There should be more to it like causes and so on if you run with --stacktrace
Usually it's a NoSuchMethod exception because some wrong dependency was put in your classloader
c
Copy code
org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget.
Caused by: org.gradle.internal.instantiation.ClassGenerationException: Could not generate a decorated class for type KotlinAndroidTarget.
Caused by: java.lang.NoClassDefFoundError: com/android/build/gradle/api/BaseVariant
Caused by: java.lang.ClassNotFoundException: com.android.build.gradle.api.BaseVariant
It seems you're right, how can I find out why it's behaving this way?
m
Mmm looks more like no AGP is loaded in your classpath
Did you apply the android plugin?
c
com.android.library
, yes
m
Interesting... Maybe it's not loaded in the same classpath as your Kotlin plugin
Make sure to put them one next to the other
If you're applying AGP in the root build.gradle.kts, put KGP next
Same if your in buildSrc, or buildscript {}
c
I tried Kotlin-then-AGP, and the opposite, same thing It's a regular project, not the root project nor buildSrc, I am referring to both plugins using a version catalog though
m
Note that by applying, I mean "load the jar" so
Copy code
plugins {
  id("com.android.application").version(foo).apply(false)
}
is also loading the jar
Apply AGP first ?
Maybe it's a simple ordering issue
c
Doesn't seem to change anything
Ah, I added the plugin with apply(false) to the root project and now it's fine
m
Welcome to classloader hell
c
🎉
598 Views