https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

jean

11/15/2023, 2:07 PM
I’m trying to modularize a kmm project but I get the following error :
Copy code
* Where:
Build file '…/build.gradle.kts' line: 91

* What went wrong:
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

* Exception is:
org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget.
    ...
    Caused by: java.lang.ClassNotFoundException: com.android.build.gradle.api.BaseVariant
	at org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader.findClass(VisitableURLClassLoader.java:186)
	... 217 more
I do have
Copy code
id("com.android.library") version androidVersion apply false
and
Copy code
resolutionStrategy {
    eachPlugin {
        if (requested.id.namespace == "com.android") {
            useModule("com.android.tools.build:gradle:$androidVersion")
        }
    }
}
in my root settings.gradle.kts and
id("com.android.library")
in build.gradle.kts of my module. The error points to line 91 which is
Copy code
androidTarget {
    compilations.all {
        kotlinOptions {
            jvmTarget = "1.8"
        }
    }
}
I did not have any problem when using only one module though. Any ideas on how to fix that?
j

jamshedalamqaderi

11/15/2023, 2:10 PM
Just try with
android()
instead of
androidTarget
j

jean

11/15/2023, 2:11 PM
I tried, the error does not come from there. (
android()
is deprecated anyway)
Well, I just had to add
id("com.android.library") apply false
to the build.gradle.kts file on root level. Little weird but it works 🤷🏻 I do have other problems with ksp now though
Could not create task :logic:compileKotlinIosArm64
(logic is the name of the module where I moved my existing code)