Hi guys! :slightly_smiling_face: We currently have...
# multiplatform
j
Hi guys! 🙂 We currently have a KMM project that is successfully shared between iOS and Android. We're now looking to see if we can also reuse it in our java backend But we've so far failed to do anything. We haven't been able to find any help online The setup is rather simple, it's a search algorithm with a levenshtein and an expect/actual for some platform specific code to remove accents from query Obviously, the shared module gradle has some dependencies on android which the backend doesn't understand. We're trying to install the android SDK on our backend dev machine just to see if that works but it seems wrong in any case. Any idea/tips as to what direction we could take to configure our setup?
c
What's the problem?
v
It's technically possible to run Android stuff on a JVM. But it's limited and has some overhead. I'd suggest properly supporting JVM instead of trying to shoehorn Android to run on a pure JVM.
Copy code
kotlin {
    android()
    iosX64()
    iosArm64()
    jvm() // Add this
}
Add
actual
implementations for JVM and that's kinda it. Run
:mymodule:jvmJar
to get a JAR and have fun. It should run on a regular JVM, instead of Android. No overhead.
s
If you've done the work to make the actuals for iOS it's probably infinitely easier to do the same for a JVM target too
j
@CLOVIS we had no idea where to even start 😅 But it seems @Vitor Hugo Schwaab that you are my savior! Not counting my chickens before they are hatched but at least it's getting me somewhere We had an hunch that building for JVM was the solution but for real, we could not find anything with a google search 😮 Anyway, I have a jar, just need to see if it's actually usable by our backend 🙂
🎉 1
c
Ah, yeah. It works basically the same for all platforms: declare the platform, fix all the missing actuals, and that should be about it. If you have a Java or Kotlin backend server in the same repository, you can then just declare a dependency on your shared module:
Copy code
plugins {
    java
}

dependencies {
    implementation(project(":your-multiplatform-module"))
}
and that's it 🙂
1