Build a Kotlin Multiplatform library

8 steps · about 2 h 48 min · Intermediate

  1. Choose what the library should share (guide, Kotlin documentation, 20 min)

    The overview frames common code, platform source sets and the targets a small library can support.

  2. Trace a project's source sets and targets (tutorial, Kotlin documentation, 24 min)

    A guided project tour makes generated folders and Gradle relationships concrete before custom code is added.

  3. Design the source-set hierarchy (doc, Kotlin documentation, 18 min)

    An intentional hierarchy avoids duplicating code between related targets or putting platform details in common code.

  4. Isolate one platform-specific capability (doc, Kotlin documentation, 22 min)

    A narrow expect and actual boundary expresses the genuine platform difference without mirroring the whole library.

  5. Add dependencies to the right source sets (doc, Kotlin documentation, 18 min)

    Dependency placement determines which APIs common and platform compilations can actually use.

  6. Configure each compilation deliberately (reference, Kotlin documentation, 20 min)

    Compilation settings make target names, language options and associations explicit and reproducible.

  7. Run common and target-specific tests (guide, Kotlin documentation, 22 min)

    The library is only portable when shared behaviour passes on each intended target and platform branches have their own coverage.

  8. Inspect and publish the target artifacts (guide, Kotlin documentation, 24 min)

    Publishing verifies coordinates, metadata and target variants from a consumer's point of view.