Search code examples
kotlin-multiplatform

What is the right project structure for a Kotlin Multiplatform (KMP) project *without* any platform specific code?


Setting up a full "KMP" / "KMM" project seems like overkill, as only the commonMain/commonTest directories would be filled.

All the other templates seem to be platform-specific.

Is there something like a "pure" Kotlin library template?


Solution

  • It would just be a module with only commonMain and commonTest. You would need at least:

    1. A Gradle module
    2. Kotlin config with multiple targets in that module
    3. Common code folders

    Whether you put the app code in the same repo or have the shared code in a separate repo is up to you. I'm not sure how much simpler you can make the config, though.

    One issue I think you'll run into is the need for platform-specific code on iOS because there are different interfaces for concurrency than you might want for a Kotlin-friendly (I.E. Android) environment. Same for things like default params.