MMKV-Kotlin-Multiplatform-Binding (abbreviated as MKMB) is a Kotlin Multiplatform wrapper for MMKV, providing high-performance key-value storage across multiple platforms.
- Windows (JVM)
- Linux (JVM)
- macOS (JVM)
- Android (JVM)
- iOS (Native)
Add the core module to your project:
dependencies {
implementation("top.kagg886.mkmb:core:${latest_version}")
}Desktop platforms require platform-specific native libraries. Requires Java 22+ (uses Project Panama for FFI).
kotlin {
sourceSets {
jvmMain.dependencies {
// Choose the platform library that matches your OS:
implementation("top.kagg886.mkmb:platform-windows:${latest_version}") // Windows
implementation("top.kagg886.mkmb:platform-linux:${latest_version}") // Linux
implementation("top.kagg886.mkmb:platform-macos:${latest_version}") // macOS
// Or detect at runtime:
val platform = when {
System.getProperty("os.name") == "Mac OS X" -> "macos"
System.getProperty("os.name").startsWith("Win") -> "windows"
System.getProperty("os.name").startsWith("Linux") -> "linux"
else -> error("Unsupported OS")
}
implementation("top.kagg886.mkmb:platform-${platform}:${latest_version}")
}
}
}Android and iOS platform binaries are automatically included with the core module. No additional dependencies needed.
For enhanced features like Kotlin Flow support, typed accessors, and more:
dependencies {
implementation("top.kagg886.mkmb:ext:${latest_version}")
}// 1. Initialize once at app startup
MMKV.initialize("/path/to/storage")
// 2. Get an instance
val kv = MMKV.defaultMMKV()
// 3. Store and retrieve values
kv.set("key", "value")
val value = kv.getString("key")For complete API documentation, visit mmkv.kagg886.top
- ✅ Initialization & configuration
- ✅ Multi-instance management (
defaultMMKV,mmkvWithID) - ✅ Type support:
Int,Long,Float,Double,Boolean,String,ByteArray,List<String> - ✅ Key operations:
remove,clear,exists,allKeys,size - ✅ Instance lifecycle:
destroy,isAlive - ✅ Encryption support
- ✅ Multi-process mode
- Android:
Parcelablestorage,SharedPreferencesmigration - iOS:
NSCodingobject storage
- 🔄 Reactive updates via
flow<T>(key) - 🎯 Type-safe accessors
- 📝 More idiomatic Kotlin API
import top.kagg886.mkmb.MMKV
import top.kagg886.mkmb.MMKVMode
// Initialize
MMKV.initialize("/data/mmkv") {
logLevel = MMKVOptions.LogLevel.Info
}
// Basic usage
val kv = MMKV.defaultMMKV()
kv.set("count", 42)
println(kv.getInt("count")) // 42
// With encryption
val encrypted = MMKV.mmkvWithID("secure", cryptKey = "my-secret-key")
encrypted.set("password", "p@ssw0rd")
// Multi-process
val shared = MMKV.mmkvWithID("shared", mode = MMKVMode.MULTI_PROCESS)See LICENSE