https://kotlinlang.org logo
m

Mihai Voicescu

11/19/2021, 5:41 PM
Having at least 1 normal Multiplatform build (js+jvm+native) + 1 Multiplatform with android seems to break the build by loading a plugin 2 times, although I used the apply false method. Any ideas how I can fix it or what am I doing wrong? `settings.gradle.kts`:
Copy code
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == "com.android") {
                useModule("com.android.tools.build:gradle:4.1.2")
            }
        }
    }
    plugins {
        id("com.android.library") apply false
        kotlin("multiplatform") version kotlin_version apply false
        kotlin("plugin.serialization") version kotlin_version apply false
subproject `build.gradle.kts`:
Copy code
plugins {
    kotlin("multiplatform")
    kotlin("plugin.serialization")
    id("com.android.library")
}

kotlin {
js {browser {

        }}}
Short trace:
Copy code
org.gradle.internal.exceptions.LocationAwareException: Build file '/Users/mihaivo/IdeaProjects/gaia/gaia-phone-client/build.gradle.kts' line: 26

Caused by: org.gradle.api.reflect.ObjectInstantiationException: Could not create an instance of type org.jetbrains.kotlin.gradle.targets.js.subtargets.KotlinBrowserJs.
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:69)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:55)
	at org.gradle.api.internal.model.DefaultObjectFactory.newInstance(DefaultObjectFactory.java:85)

Caused by: java.lang.IllegalStateException: The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build. 
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
See: <https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl>
	at org.jetbrains.kotlin.gradle.targets.js.MultiplePluginDeclarationDetector.detect(MultiplePluginDeclarationDetector.kt:26)
	at org.jetbrains.kotlin.gradle.targets.js.MultiplePluginDeclarationDetector$Companion.detect(MultiplePluginDeclarationDetector.kt:52)
	at org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin.apply(NodeJsRootPlugin.kt:23)
h

hfhbd

11/19/2021, 6:42 PM
Why do you use the resolution strategy block at all? Since AGP 4.2.0 you can use the build-in Gradle plugin block: See https://github.com/hfhbd/ComposeTodo/blob/main/build.gradle.kts
m

Mihai Voicescu

11/19/2021, 6:52 PM
Same problem even if I remove it and use
Copy code
id("com.android.library") version "7.0.3" apply false
h

hfhbd

11/20/2021, 12:25 AM
How exactly do your build files look like?
m

Mihai Voicescu

11/22/2021, 9:21 AM
The minimum to screw up the build is this
2 Views