Build a Kotlin Multiplatform library
8 steps · about 2 h 48 min · Intermediate
- 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.
- 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.
- 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.
- 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.
- Add dependencies to the right source sets (doc, Kotlin documentation, 18 min)
Dependency placement determines which APIs common and platform compilations can actually use.
- Configure each compilation deliberately (reference, Kotlin documentation, 20 min)
Compilation settings make target names, language options and associations explicit and reproducible.
- 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.
- 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.