why is it when I create a new multiplatform projec...
# multiplatform
c
why is it when I create a new multiplatform project with an android app, I get the following issue with gradle:
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
c
I have not seen the
java
plugin being applied by default in the mp project. Why do you need to apply the
java
plugin?
c
I don't. It was literally a project generated by the wizard
c
🤔 which wizard are you using?
c
the kotlin multiplatform one that comes as part of the kotlin multiplatform plugin
(New project wizard)
c
Are you using Android Studio or IntelliJ, and which version? When I tried it, it did not apply the
java
plugin.
c
IntelliJ IDEA 2023.2 EAP (Ultimate Edition) Build #IU-232.6734.9, built on June 1, 2023 Expiration date: July 1, 2023 Runtime version: 17.0.7+7-b966.2 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.19.0-43-generic GC: G1 Young Generation, G1 Old Generation Memory: 16384M Cores: 16 Registry: debugger.new.tool.window.layout=true ide.experimental.ui=true kotlin.wasm.wizard=true ide.images.show.chessboard=true Non-Bundled Plugins: com.intellij.plugins.expui (0.4) com.intellij.nativeDebug (232.6734.4) com.github.oowekyala.javacc (1.10) com.tang (1.4.3-IDEA231) Pythonid (232.6734.9) com.demonwav.minecraft-dev (2023.2-1.6.5) org.jetbrains.compose.desktop.ide (1.4.0) org.jetbrains.plugins.kotlin.jupyter (232.6734.9) androidx.compose.plugins.idea (232.6734.9) Kotlin: 232-1.8.21-release-380-IJ6734.9 Current Desktop: ubuntu:GNOME
it doesn't explicitly apply it
j
Do you have
jvm { withJava() }
or just
jvm()
?
c
Copy code
jvm {
        jvmToolchain(11)
        testRuns.named("test") {
            executionTask.configure {
                useJUnitPlatform()
            }
        }
    }
should I zip up a project?
c
Yeah
Or just the build gradle snippet should be fine
c
the topography of the project from the wizard
the generated build.gradle:
Copy code
plugins {
    kotlin("multiplatform") version "1.8.21"
    application
    id("com.android.application")
}

group = "from.wizard"
version = "1.0-SNAPSHOT"

repositories {
    google()
    mavenCentral()
    maven("<https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven>")
}

kotlin {
    jvm {
        jvmToolchain(11)
        testRuns.named("test") {
            executionTask.configure {
                useJUnitPlatform()
            }
        }
    }
    js {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport {
                    enabled.set(true)
                }
            }
        }
    }
    android()
    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val jvmMain by getting {
            dependencies {
                implementation("io.ktor:ktor-server-netty:2.0.2")
                implementation("io.ktor:ktor-server-html-builder-jvm:2.0.2")
                implementation("org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2")
            }
        }
        val jvmTest by getting
        val jsMain by getting {
            dependencies {
                implementation("org.jetbrains.kotlin-wrappers:kotlin-react:18.2.0-pre.346")
                implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:18.2.0-pre.346")
                implementation("org.jetbrains.kotlin-wrappers:kotlin-emotion:11.9.3-pre.346")
            }
        }
        val jsTest by getting
        val androidMain by getting
        val androidTest by getting {
            dependencies {
                implementation("junit:junit:4.13.2")
            }
        }
    }
}

android {
    namespace = "from.wizard.application"
    compileSdk = 32
    defaultConfig {
        applicationId = "from.wizard.application"
        minSdk = 24
        targetSdk = 32
        versionCode = 1
        versionName = "1.0"
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = false
        }
    }
}

application {
    mainClass.set("from.wizard.application.ServerKt")
}

tasks.named<Copy>("jvmProcessResources") {
    val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
    from(jsBrowserDistribution)
}

tasks.named<JavaExec>("run") {
    dependsOn(tasks.named<Jar>("jvmJar"))
    classpath(tasks.named<Jar>("jvmJar"))
}
settings.gradle
Copy code
pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.namespace == "com.android") {
                useModule("com.android.tools.build:gradle:7.3.1")
            }
        }
    }
}
rootProject.name = "fromwizard"
c
You are applying
application
, which is not compatible with the Android plugin. At least it was not compatible back when I tried this last, which was probably last year. Let me see if I can find the thread.
c
Ace. Commenting out all things related to that appears to fix it.
c
What I ended up doing was I created a new module that had the JVM target with the application/java plugin. Then this module consumed the JVM target of the KMP project.
c
so if I wanted to make a mutiplatform project with a jvm executable and an android app, I can't use the application plugin?
that sounds more preferable
In my defence, if I go through the default option of full stack web application and hit next, I get common, jvm, js and android, so there's always going to be peanut butter in my chocolate. That feels like it should be captured as an issue somewhere
c
I agree. Here is a thread where they mention this issue, albeit in the context of compose.
c
let me get my shovel