Thread
#multiplatform
    Mihai Voicescu

    Mihai Voicescu

    10 months ago
    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:
    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:
    plugins {
        kotlin("multiplatform")
        kotlin("plugin.serialization")
        id("com.android.library")
    }
    
    kotlin {
    js {browser {
    
            }}}
    Short trace:
    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)
    hfhbd

    hfhbd

    10 months ago
    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
    Mihai Voicescu

    Mihai Voicescu

    10 months ago
    Same problem even if I remove it and use
    id("com.android.library") version "7.0.3" apply false
    hfhbd

    hfhbd

    10 months ago
    How exactly do your build files look like?
    Mihai Voicescu

    Mihai Voicescu

    10 months ago
    The minimum to screw up the build is this