kmp-settings
Type-safe settings management for Kotlin Multiplatform with declarative UI generation.

Features
- Declarative settings: Define settings with
@Setting and @Persisted annotations on data class properties
- Auto-generated schema: KSP processor generates type-safe
SettingsSchema with field metadata
- Built-in persistence: DataStore-based storage with support for primitives, collections, enums, and serialized objects
- Auto-generated UI:
AutoSettingsScreen composable renders settings from schema with zero boilerplate
- Cross-platform: Android, iOS, JVM (Desktop), and Linux support with platform-specific visibility controls
- Backup/restore: JSON export/import with checksum validation and schema versioning
- Advanced features: Field dependencies, validation rules, confirmation dialogs, undo/redo, reset management
Installation
dependencies {
implementation("io.github.mlmgames:kmp-settings-core:<version>")
ksp("io.github.mlmgames:kmp-settings-ksp:<version>")
implementation("io.github.mlmgames:kmp-settings-ui-compose:<version>")
}
Requirements:
- Android minSdk 21
- Java 17+ for KSP processor
Quick Start
1. Define your settings
2. Build to generate schema
The KSP processor generates AppSettingsSchema automatically.
3. Create repository and UI
Usage
Supported Field Types
Platform-Specific Settings
@Setting(
title = "Android-only Feature",
category = General::class,
type = Toggle::class,
platforms = [SettingPlatform.ANDROID] // Hidden on iOS/Desktop
)
val androidFeature: Boolean = false
Field Dependencies
@Setting(
title = "Enable Notifications",
category = General::class,
type = Toggle::class
)
val notificationsEnabled: Boolean = false
@Setting(
title = "Notification Sound",
category = General::class,
type = Toggle::class,
dependsOn = "notificationsEnabled" // Disabled when above is false
)
val notificationSound: Boolean = true
Validation & Confirmation
@Setting(
title = "Server URL",
category = General::class,
type = TextInput::class
)
@Pattern("^https?://.*")
val serverUrl: String = "https://api.example.com"
@Setting(
title = "Delete All Data",
category = General::class,
type = Button::class
)
@RequiresConfirmation(
title = "Confirm Deletion",
message = ,
isDangerous = true
)
deleteData: =
Backup & Restore
Custom UI Types
AutoSettingsScreen(
schema = AppSettingsSchema,
value = settings,
onSet = viewModel::updateSetting,
customTypeHandlers = listOf(
CustomTypeHandler(
typeClass = ColorPicker::class,
render = { field, meta, value, enabled, onSet ->
val color = (field as SettingField<AppSettings, String>).get(value)
ColorPickerButton(
color = color,
enabled = enabled,
onColorSelected = { onSet(field.name, it) }
)
}
)
)
)
Contributing
Development setup:
git clone https://github.com/mlmgames/kmp-settings.git
cd kmp-settings
./gradlew build
The project uses Gradle with Kotlin DSL. Tests might be added later as *Test.kt files alongside source.
To publish locally for testing:
./gradlew publishToMavenLocal
Support
License
Apache License 2.0 - See LICENSE for details.