Android Developers Blog
The latest Android and Google Play news for app and game developers.
🔍
Platform Android Studio Google Play Jetpack Kotlin Docs News

10 October 2022

Announcing an Experimental Preview of Jetpack Multiplatform Libraries


Link copied to clipboard

Posted by Márton Braun, Developer Relations Engineer

Since we announced Kotlin support for Android in 2017, developers have been excited about writing their Android apps using Kotlin. We’ve continuously expanded this support for the language over the years, going Kotlin-first with Jetpack libraries and documentation, and then further investing into Kotlin with Jetpack Compose. We’ve also seen the interest of the community in Kotlin’s multiplatform capabilities.

Kotlin Multiplatform Mobile from JetBrains is now in beta, and we have been experimenting with this technology to see how it can enable code sharing across platforms. As part of these experiments, we are now sharing a preview of Kotlin Multiplatform libraries in Jetpack.

The libraries available for multiplatform as part of this experimental preview are Collections and DataStore. These were chosen as they evaluate several important aspects of converting an existing library to multiplatform:

  • Collections is an example of a library written in the Java programming language that has no Android-specific dependencies, but implements Java collection APIs.
  • DataStore is written entirely in Kotlin, and it uses coroutines in both its implementation and APIs. It also depends on Java IO and Android platform APIs.

With this preview, we’re looking for your feedback about using these Jetpack libraries in multiplatform projects targeting Android and iOS applications. Keep in mind that these dev builds are experimental and should not be used in production. They are published outside the regular release cycle of these libraries, and they are not guaranteed to graduate to stable.

The libraries are available from Google’s Maven repository. To start using them, add the following dependencies to your Kotlin Multiplatform project:

val commonMain by getting {
  dependencies {
      implementation("androidx.collection:collection:1.3.0-dev01")

      // Lower-level APIs with support for custom serialization
      implementation("androidx.datastore:datastore-core-okio:1.1.0-dev01")
      // Higher-level APIs for storing values of basic types
      implementation("androidx.datastore:datastore-preferences-core:1.1.0-dev01")
  }
}

You can learn more about the available APIs by checking out our sample app which uses DataStore on Android and iOS, or in the preview API reference documentation available for both libraries.

To provide feedback about your experience with the multiplatform Jetpack libraries, or to show your interest in Kotlin Multiplatform, join the conversation in the Kotlinlang #multiplatform channel. You can also open bugs on the issue tracker for DataStore or for Collections.

*Java is a trademark or registered trademark of Oracle and/or its affiliates.