Add dependencies to your project
You've created and tweaked your first Kotlin Multiplatform project! Now let's learn how to add dependencies to third-party libraries, which is necessary for building successful cross-platform applications.
Dependency types
There are two types of dependencies that you can use in Kotlin Multiplatform projects:
Multiplatform dependencies. These are multiplatform libraries that support multiple targets and can be used in the common source set,
commonMain.Many modern Android libraries already have multiplatform support, like Koin, Coil, and SQLDelight. Find more multiplatform libraries on klibs.io, a search service offered by JetBrains for discovering Kotlin Multiplatform libraries.
Native dependencies. These are regular libraries from specific ecosystems. In native projects you usually work with them, for example, using Gradle for Android and Swift Package Manager for iOS.
When you work with a multiplatform project module, typically, you still need native dependencies to use platform APIs such as security storage, specific system calls, and so on. In the build script, you specify native dependencies in the configuration of native source sets, for example,
androidMainandiosMain.
For both types of dependencies, you can use local and external repositories.
Add a multiplatform dependency
Let's make the greeting a little more festive: In addition to the OS version, add a function to display the number of days left until New Year's Day. The kotlinx-datetime library, which has full multiplatform support, is the most convenient way to work with dates in your shared code.
Open the
gradle/libs.versions.tomlfile and add thekotlinx-datetimedependency to the version catalog:[versions] kotlinx-datetime = "0.8.0" [libraries] kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinx-datetime" }Open the
sharedLogic/build.gradle.ktsfile and add a reference to that library entry to the section that configures the common code source set:kotlin { //... sourceSets { commonMain.dependencies { implementation(libs.kotlinx.datetime) } } }Select the Build | Sync Project with Gradle Files menu item or click the Sync Gradle Changes button in the build script editor to synchronize Gradle files:

Call a kotlinx-datetime API
With the dependency added, you can add date and time calculations to your common code:
Right-click the
sharedLogic/src/commonMain/.../greetingkmpdirectory and select New | Kotlin Class/File to create a new file,NewYear.kt.In
NewYear.kt, add two functions that calculate the number of days from today until the start of next year using thedatetimedate arithmetic and form the phrase to be displayed:fun daysUntilNewYear(): Int { val today = Clock.System.todayIn(TimeZone.currentSystemDefault()) val closestNewYear = LocalDate(today.year + 1, 1, 1) return today.daysUntil(closestNewYear) } fun daysPhrase(): String = "There are only ${daysUntilNewYear()} days left until New Year! 🎆"Add all necessary imports as suggested by the IDE. Make sure to import
kotlin.time.Clock, notkotlinx.datetime.Clock.In the
Greeting.ktfile, update theGreetingclass to see the result:class Greeting { private val platform: Platform = getPlatform() fun greet(): List<String> = buildList { add(if (Random.nextBoolean()) "Hi!" else "Hello!") add("Guess what this is! > ${platform.name.reversed()}!") add(daysPhrase()) } }To see the results, re-run your androidApp and iosApp run configurations from IntelliJ IDEA:

Next step
In the next part of the tutorial, you'll add more dependencies and more complex logic to your project.
See also
Discover how to work with multiplatform dependencies of all kinds: Kotlin libraries, Kotlin Multiplatform libraries, and other multiplatform projects.
Learn how to add Android dependencies and iOS dependencies with or without CocoaPods for use in platform-specific source sets.
Check out the examples of how to use Android and iOS libraries in sample projects.
Get help
Kotlin Slack. Get an invite and join the #multiplatform channel.
Kotlin issue tracker. Report a new issue.