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

James Black

04/23/2022, 3:50 AM
I am working on my KMM backend server and I got this error:
Copy code
The 'java' plugin has been applied, but it is not compatible with the Android plugins.
In my shared build.gradle I have this. If I just use jvm() instead no issues, except it goes to androidMain not jvmMain.
Copy code
kotlin {
    android()
    jvm {
        withJava()
    }
I have a sinking feeling it won't be resolved any time soon based on this issue: https://youtrack.jetbrains.com/issue/KT-30878 Is the best bet to just have web and server have one KMM project and android/iOS and everything else have the other, or should servers just not be in the KMM project currently?
e

ephemient

04/23/2022, 11:42 PM
kotlin { android() jvm() }
works as long as you avoid `kotlin.jvm.withJava()`; do you need it?
j

James Black

04/23/2022, 11:45 PM
I would prefer to have the server code get info from jvmMain but I am stuck with it pulling from androidMain. I just minimize what it needs from shared.
e

ephemient

04/23/2022, 11:46 PM
I'm not sure what you're doing exactly, but I would not use the same MPP project for multiple binaries. common code in MPP, then separate project for Android, JVM, and web applications.
j

James Black

04/23/2022, 11:49 PM
Yes. My server project connects to androidMain. Each common project has its own Platform class so I can tell. I have iOS and Android also separate but all connect to a shared project. It is my backend server that has a problem.
e

ephemient

04/23/2022, 11:52 PM
if your backend is pulling in the wrong configuration without
withJava()
, it sounds like a dependency issue that is better resolved there rather than using
withJava()
here as a workaround
is that the only reason you need it or is there something else? yeah, there probably is not any road to making
android
and
jvm.withJava()
work together
j

James Black

04/24/2022, 1:16 AM
You can look at https://github.com/jblack975/MyOutfitPicker and see how it is set up. When I start up the server I get this output.
Copy code
Wrong shared subproject.
Due to this:
Copy code
try {
    val s = println(Platform().platform)
} catch(e:Throwable) { println("Wrong shared subproject.")}
It tries to execute this line:
Copy code
actual val platform: String = "Android ${android.os.Build.VERSION.SDK_INT}"
e

ephemient

04/24/2022, 2:03 AM
what kotlin version are you using? it's not in the repo
I see your server is using kotlin-platform-jvm; this is deprecated and should not be used
if I set kotlinVersion=1.6.10 and remove that plugin, the server looks like it picks up the right variant
j

James Black

04/24/2022, 6:17 AM
When I try and have it as this, and have the commented out line in the jvmMain project, then API_KEY is "88888", so without the plugin it still doesn't work.
Copy code
val apiKey = "88888"//BuildKonfig.api_key

val weatherClientApiKey = BuildKonfig.weather_client_api_key
actual class Platform actual constructor() {
    actual val platform: String = "Android "

}
So regardless, with or without the plugin it still goes to shared/androidMain, not jvmMain, with Kotlin 1.6.10 or 1.6.20. Thanks for trying though. Guessing it will just be broken for the foreseeable future.
4 Views