AppState Part of Android Jetpack.
Jetpack AppState is a group of libraries that helps you extend Jetpack Compose
State beyond the UI layer so you can transform and share
reactive state across any layer of your app. AppState consists of two main
libraries:
- Transform: A library built on the Compose runtime
that runs a
@Composableblock without a UI to combine and transform state sources into ComposeState. - StateStore: A type-safe container that stores and
exposes shared app state as Compose
State. It's most commonly used to share state across multiple application components.
To learn how Compose State works outside UI composables and how Transform
and StateStore fit alongside existing Compose APIs such as mutableStateOf and
SavedStateHandle.saveable across your architecture, see Use Compose State
outside the UI.
Artifacts
To get started with AppState, add the artifacts your project needs along with any supporting libraries:
| Name | What it does | Artifact |
|---|---|---|
| Transform | Produces and observes Compose State outside the UI (transform and listener). |
androidx.appstate.transform:transform |
| Transform Testing | Testing utilities for Transform (transformTest and TransformTestScope). |
androidx.appstate.transform:transform-testing |
| StateStore | Core type-safe state container and StateStoreKey definitions. |
androidx.appstate.statestore:statestore |
| StateStore DataStore integration | Persists and restores StateStore keys to disk using Jetpack DataStore. |
androidx.appstate.statestore:statestore-datastore |
| Compose Compiler plugin | Compiles @Composable functions and blocks in modules that use transform or listener. |
org.jetbrains.kotlin.plugin.compose |
| KotlinX Serialization plugin | Generates serializers for @Serializable StateStoreKey and custom state types when using statestore-datastore. |
org.jetbrains.kotlin.plugin.serialization |
| KotlinX Serialization library | Runtime serialization library for @Serializable StateStoreKey and custom state types when using statestore-datastore. |
org.jetbrains.kotlinx:kotlinx-serialization-core |
Project setup
To add the AppState libraries to your project, declare the versions, libraries,
and Gradle plugins in your libs.versions.toml file:
[versions]
appstate = "1.0.0-alpha01"
kotlin = "2.4.10"
kotlinxSerializationCore = "1.11.0"
[libraries]
# Transform library for producing and observing Compose State
androidx-appstate-transform = { module = "androidx.appstate.transform:transform", version.ref = "appstate" }
# Testing utilities for Transform
androidx-appstate-transform-testing = { module = "androidx.appstate.transform:transform-testing", version.ref = "appstate" }
# Core StateStore library
androidx-appstate-statestore = { module = "androidx.appstate.statestore:statestore", version.ref = "appstate" }
# DataStore integration for StateStore (and required serialization runtime)
androidx-appstate-statestore-datastore = { module = "androidx.appstate.statestore:statestore-datastore", version.ref = "appstate" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinxSerializationCore" }
[plugins]
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
# Required only when using statestore-datastore
jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
Next, configure your module's build.gradle.kts file:
plugins {
...
alias(libs.plugins.compose.compiler)
// Required only when using statestore-datastore
alias(libs.plugins.jetbrains.kotlin.serialization)
}
android {
...
buildFeatures {
compose = true
}
}
dependencies {
...
implementation(libs.androidx.appstate.transform)
implementation(libs.androidx.appstate.statestore)
// Optional: DataStore integration for StateStore
implementation(libs.androidx.appstate.statestore.datastore)
implementation(libs.kotlinx.serialization.core)
...
testImplementation(libs.androidx.appstate.transform.testing)
}
Code samples
The AppState recipes repository contains working examples demonstrating how to use Transform and StateStore across common Android architecture patterns and form factors.
Provide feedback
Share your feedback, report bugs, or request features using the Transform issue tracker or StateStore issue tracker.