Skip to main content
Setting up DataStore in Kotlin Multiplatform typically requires platform-specific code for each target. FileKit simplifies this by providing a unified path API.

The Problem

The official DataStore setup requires expect/actual declarations with platform-specific implementations:
  • Android needs Context.filesDir
  • iOS needs NSDocumentDirectory
  • JVM needs System.getProperty("java.io.tmpdir") or a custom path
This means writing and maintaining code in androidMain, iosMain, and jvmMain source sets.

The Solution

With FileKit, you can define everything in commonMain:
That’s it! No platform-specific code needed.

Complete Example

Here’s a complete setup for a preferences manager:

Why databasesDir?

FileKit.databasesDir returns a platform-appropriate location for persistent data: This ensures your preferences are stored in a safe, persistent location on each platform.

Dependencies

Add the DataStore dependencies alongside FileKit Core: