i keep getting "The 'java' plugin has been applied, but it is not compatible with the Android plugin...
y
i keep getting "The 'java' plugin has been applied, but it is not compatible with the Android plugins."
build.gradle.kts
Copy code
plugins {
    kotlin("multiplatform") version "1.7.0"
    application
    id("com.android.application")
    id("kotlin-android-extensions")
}

group = "net.virtualcoder"
version = "1.0-SNAPSHOT"

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

kotlin {
    jvm {
        compilations.all {
            kotlinOptions.jvmTarget = "1.8"
        }
        testRuns["test"].executionTask.configure {
            useJUnitPlatform()
        }
    }
    js(LEGACY) {
        binaries.executable()
        browser {
            commonWebpackConfig {
                cssSupport.enabled = 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.1")
                implementation("io.ktor:ktor-server-html-builder-jvm:2.0.1")
                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.0.0-pre.332-kotlin-1.6.21")
                implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom:18.0.0-pre.332-kotlin-1.6.21")
                implementation("org.jetbrains.kotlin-wrappers:kotlin-emotion:11.9.0-pre.332-kotlin-1.6.21")
            }
        }
        val jsTest by getting
        val androidMain by getting {
            dependencies {
                implementation("com.google.android.material:material:1.5.0")
            }
        }
        val androidTest by getting {
            dependencies {
                implementation("junit:junit:4.13.2")
            }
        }
    }
}

android {
    compileSdkVersion(31)
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        applicationId = "net.virtualcoder.application"
        minSdkVersion(24)
        targetSdkVersion(31)
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
}

application {
    mainClass.set("net.virtualcoder.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"))
}
e
can't use
application
plugin
l
More specifically, you can’t application and android plugins in the same module.
e
even without the Android plugin, it won't work with the KMP JVM target unless you explicitly add
withJava
y
oh i just used the idea ultimate wizard to create the fullstack project and added an android target
l
It would be better to have a module for shared code, then a module for android that has just an entry point into your shared module and a jvm module with application that just has an entrypoint.
e
you can't use
withJava
and Android
yes, I agree. use KMP for a shared library. if you want to have an Android application and a JVM application, create separate single-platform modules for them
y
sounds good thanks a lot
l
I personally always keep the full android app in the shared module and have entry points for other platforms, but that may just be because I’m lazy.
That said, it would be nice if we could have android and jvm applications in one module, but I get why Google set the android plugin to fail if it sees the java plugin.
e
even if it didn't explicitly fail, it would be broken in other ways, so it's just as well that it errors out early
l
It would be nice if it were programmed to be compatible. I’m sure it’s possible to do, but would require a fair bit of work.
y
well right now im trying everything since i can't find an official "fullstack/android" kmp hello world. Found some finished projects on github though so ill just use those as an example for structure
s
Do any of these fit your needs? More specifically peopleInSpace maybe if you don’t want to filter through a lot of them.
1336 Views