When implementing state in Jetpack Compose, Android Studio may report “Unresolved reference: mutableStateOf”.
Unresolved reference: mutableStateOf
mutableStateOf is part of Jetpack Compose Runtime. The error usually means that the required import is missing, Compose Runtime is unavailable to the module, Compose is not configured correctly, or Gradle Sync has failed.
Google’s current Compose documentation describes mutableStateOf as creating an observable MutableState<T> integrated with the Compose runtime. When its value changes, Compose schedules recomposition for Composables that read that value. :contentReference[oaicite:15]{index=15}
This article explains how to fix the missing import, verify Compose Runtime, use remember correctly, configure delegated state, and diagnose Gradle or multi-module problems.
- What Does “Unresolved reference: mutableStateOf” Mean?
- What Does mutableStateOf Do?
- Common Situations
- Cause 1: mutableStateOf Is Not Imported
- Solution 1: Add the Correct Import
- Cause 2: Delegate Imports Are Missing
- Solution 2: Add the Complete State Imports
- Cause 3: Compose Runtime Is Missing
- Solution 3: Check the Compose BOM
- Solution 4: Check Compose Runtime Directly
- Cause 4: Compose Is Not Enabled for the Module
- Solution 5: Enable the Compose Build Feature
- Cause 5: Compose Code Was Moved to a Non-Compose Module
- Solution 6: Configure the Module That Contains the Compose Code
- Cause 6: Gradle Sync Failed
- Solution 7: Run Gradle Sync
- Solution 8: Build from the Command Line
- Cause 7: remember and mutableStateOf Are Being Confused
- Solution 9: Use remember with mutableStateOf in a Composable
- Can You Use mutableStateOf Without remember?
- Correct Basic Pattern
- Cause 8: Using Compose State in a Normal Kotlin State Holder
- Cause 9: The Import Is Missing in a ViewModel
- Cause 10: Only MutableState Was Imported
- Cause 11: Confusing mutableStateOf with Primitive State APIs
- Solution 10: Match the Import to the Function
- Cause 12: Copying an Incomplete rememberSaveable Example
- Solution 11: Check rememberSaveable Imports
- Cause 13: Android Studio Does Not Offer the Auto Import
- Solution 12: Optimize and Re-add Imports
- Cause 14: Only the IDE Shows the Error
- Solution 13: Resynchronize the IDE
- Cause 15: A Compose Compiler Configuration Problem Exists
- Using State.value Directly
- Using the by Syntax
- Using Destructuring Syntax
- Be Careful with Mutable Collections
- Should a ViewModel Use mutableStateOf or StateFlow?
- Minimal mutableStateOf Example
- Minimal Delegated-State Example
- Fastest Troubleshooting Order
- If the Error Still Occurs
- Summary
What Does “Unresolved reference: mutableStateOf” Mean?
In Kotlin, an unresolved reference means that the compiler cannot locate a declaration matching the name used in the source code.
Compose’s mutableStateOf function is located at:
androidx.compose.runtime.mutableStateOf
The normal import is:
import androidx.compose.runtime.mutableStateOf
It is commonly used with remember:
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember
@Composable
fun CounterScreen() {
val count = remember {
mutableStateOf(0)
}
}
First check: Place the cursor on mutableStateOf and confirm that Android Studio offers androidx.compose.runtime.mutableStateOf as an import.
What Does mutableStateOf Do?
mutableStateOf creates a MutableState<T> object that Compose can observe.
val count = mutableStateOf(0)
Read its value with:
count.value
and update it with:
count.value++
Google’s current documentation states that when a Compose MutableState value changes, recomposition is scheduled for Composables that read that value. :contentReference[oaicite:16]{index=16}
Common Situations
- Adding state to a Compose screen for the first time
- Typing
mutableStateOfmanually - Copying Compose code from another project
- Adding Compose to an XML-based Android project
- Moving Compose code into another module
- Changing Compose Runtime dependencies
- Changing or removing the Compose BOM
- Working after a failed Gradle Sync
- Changing Kotlin or Compose-related plugins
- Seeing
rememberresolve whilemutableStateOfremains unresolved
Cause 1: mutableStateOf Is Not Imported
This is the most common cause.
Check for:
import androidx.compose.runtime.mutableStateOf
Solution 1: Add the Correct Import
import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember
Example:
@Composable fun SampleScreen() { val checked = remember { mutableStateOf(false) } }
Cause 2: Delegate Imports Are Missing
A common Compose pattern is:
var count by remember { mutableStateOf(0) }
The by syntax also requires:
import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue
Google’s current Compose state documentation explicitly lists these imports for property-delegated state. :contentReference[oaicite:17]{index=17}
Solution 2: Add the Complete State Imports
import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue
Then:
@Composable fun CounterScreen() { var count by remember { mutableStateOf(0) }
Button(
onClick = {
count++
}
) {
Text("Count: $count")
}
}
Cause 3: Compose Runtime Is Missing
mutableStateOf belongs to Compose Runtime, not Material 3.
If the module cannot access Compose Runtime, the import cannot be resolved.
Solution 3: Check the Compose BOM
Google’s current Compose setup documentation recommends using the Compose BOM to keep Compose library versions aligned. The current documentation includes a 2026.06.00 BOM example. :contentReference[oaicite:18]{index=18}
Kotlin DSL example:
dependencies { val composeBom = platform( "androidx.compose:compose-bom:2026.06.00" )
implementation(composeBom)
androidTestImplementation(composeBom)
implementation(
"androidx.compose.material3:material3"
)
}
For an existing application, keep the BOM version consistent with the rest of that project’s dependency configuration.
Recommended: Avoid arbitrarily mixing unrelated versions of Compose Runtime, UI, Foundation, and Material libraries when a BOM can manage their compatibility.
Solution 4: Check Compose Runtime Directly
To verify that Runtime is available:
dependencies { implementation( "androidx.compose.runtime:runtime" ) }
When the Compose BOM is imported, a separate version does not need to be specified on the Runtime dependency.
Cause 4: Compose Is Not Enabled for the Module
This commonly happens after adding Compose source code to an older View/XML project or moving UI code into another Android module.
Check:
android { buildFeatures { compose = true } }
Google’s current setup documentation also enables Compose through the Android module’s build features. :contentReference[oaicite:19]{index=19}
Solution 5: Enable the Compose Build Feature
Kotlin DSL:
android { buildFeatures { compose = true } }
Groovy:
android { buildFeatures { compose true } }
Run Gradle Sync after changing the configuration.
Cause 5: Compose Code Was Moved to a Non-Compose Module
In a multi-module project:
:app :feature-home :domain
:app may have Compose dependencies while :feature-home does not.
If Compose code is moved into the latter module, mutableStateOf may become unresolved there.
Solution 6: Configure the Module That Contains the Compose Code
android { buildFeatures { compose = true } }
dependencies {
implementation(
platform("androidx.compose:compose-bom:2026.06.00")
)
implementation(
"androidx.compose.runtime:runtime"
)
}
The relevant module itself needs access to Compose Runtime.
Cause 6: Gradle Sync Failed
Even a correct import can appear unresolved if Gradle has not successfully resolved Compose dependencies.
Solution 7: Run Gradle Sync
File → Sync Project with Gradle Files
If another error appears during Sync, fix that error first.
Common upstream problems include:
- Could not resolve dependency errors
- Missing Gradle plugins
- Repository configuration errors
- Kotlin plugin errors
- Compose compiler configuration errors
Solution 8: Build from the Command Line
macOS or Linux:
./gradlew assembleDebug
Windows:
gradlew.bat assembleDebug
If Gradle reports dependency-resolution problems, fix those before treating the error as an IDE issue.
Cause 7: remember and mutableStateOf Are Being Confused
They have different responsibilities:
mutableStateOf → Creates observable MutableState
remember
→ Keeps an object in the Composition
Google’s current documentation commonly uses them together as remember { mutableStateOf(...) }. :contentReference[oaicite:20]{index=20}
Solution 9: Use remember with mutableStateOf in a Composable
@Composable fun CounterScreen() { val count = remember { mutableStateOf(0) } }
or:
@Composable fun CounterScreen() { var count by remember { mutableStateOf(0) } }
Can You Use mutableStateOf Without remember?
This is syntactically possible:
@Composable fun CounterScreen() { val count = mutableStateOf(0) }
However, creating the state object directly during Composition means a new state object can be created again during recomposition.
Google’s Compose State codelab demonstrates this issue and then fixes it by wrapping mutableStateOf in remember. :contentReference[oaicite:21]{index=21}
Correct Basic Pattern
@Composable fun CounterScreen() { var count by remember { mutableStateOf(0) }
Column {
Text(
text = "Count: $count"
)
Button(
onClick = {
count++
}
) {
Text("Add")
}
}
}
When count changes, Compose can schedule recomposition for code that reads the state. :contentReference[oaicite:22]{index=22}
Cause 8: Using Compose State in a Normal Kotlin State Holder
mutableStateOf itself can be used outside a Composable when Compose Runtime is available.
For example:
class CounterState { var count by mutableStateOf(0) }
This differs from remember, which stores an object in the Composition and therefore requires a Composable context.
Important distinction: mutableStateOf is a Compose Runtime state API, while remember is specifically tied to the Composition.
Cause 9: The Import Is Missing in a ViewModel
If a ViewModel intentionally uses Compose State, it still needs:
import androidx.compose.runtime.mutableStateOf
Example:
class MainViewModel : ViewModel() {
var text = mutableStateOf("")
private set
fun updateText(value: String) {
text.value = value
}
}
Depending on the architecture, a ViewModel may instead expose StateFlow and let the UI collect it. The unresolved-reference error itself, however, is still an import or dependency-resolution problem.
Cause 10: Only MutableState Was Imported
This import:
import androidx.compose.runtime.MutableState
does not automatically import the factory function.
You still need:
import androidx.compose.runtime.mutableStateOf
Cause 11: Confusing mutableStateOf with Primitive State APIs
Compose Runtime also provides optimized primitive state functions.
Google’s current Compose State codelab mentions:
mutableIntStateOf mutableLongStateOf mutableFloatStateOf mutableDoubleStateOf
as primitive-specific variants. :contentReference[oaicite:23]{index=23}
For example:
var count by remember { mutableIntStateOf(0) }
Solution 10: Match the Import to the Function
For mutableIntStateOf:
import androidx.compose.runtime.mutableIntStateOf
It is a separate API from mutableStateOf.
Cause 12: Copying an Incomplete rememberSaveable Example
Code such as:
var name by rememberSaveable { mutableStateOf("") }
requires several imports.
Solution 11: Check rememberSaveable Imports
import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue
Google’s state documentation explains that rememberSaveable retains saveable state across recompositions and can also restore it across Activity recreation and related saved-state scenarios. :contentReference[oaicite:24]{index=24}
Cause 13: Android Studio Does Not Offer the Auto Import
Even when the Gradle configuration is correct, auto-import suggestions can occasionally fail to appear.
Add the import manually:
import androidx.compose.runtime.mutableStateOf
Solution 12: Optimize and Re-add Imports
Use Android Studio’s Optimize Imports if the source file contains conflicting or stale imports, then add the required Compose Runtime imports again.
Cause 14: Only the IDE Shows the Error
If the command-line Gradle build succeeds but Android Studio still highlights mutableStateOf in red, the IDE’s project model or index may be stale.
Solution 13: Resynchronize the IDE
Try this order:
- Gradle Sync
- Build → Rebuild Project
- Restart Android Studio
Confirm the Gradle build itself is healthy before assuming an IDE cache problem.
Cause 15: A Compose Compiler Configuration Problem Exists
Modern Kotlin and Compose projects may use the Compose Compiler Gradle Plugin.
However, mutableStateOf itself is a Runtime API, so for an unresolved reference error, imports and Runtime dependencies should be checked first.
A compiler-plugin problem normally causes additional Compose compilation errors as well.
Using State.value Directly
You do not have to use Kotlin property delegates.
@Composable fun CounterScreen() { val count = remember { mutableStateOf(0) }
Button(
onClick = {
count.value++
}
) {
Text(
text = "Count: ${count.value}"
)
}
}
This form does not require getValue or setValue.
Using the by Syntax
@Composable fun CounterScreen() { var count by remember { mutableStateOf(0) }
Button(
onClick = {
count++
}
) {
Text(
text = "Count: $count"
)
}
}
This form requires:
import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue
as documented by Google. :contentReference[oaicite:25]{index=25}
Using Destructuring Syntax
Another valid form is:
@Composable fun CounterScreen() { val (count, setCount) = remember { mutableStateOf(0) }
Button(
onClick = {
setCount(count + 1)
}
) {
Text("Count: $count")
}
}
Google’s current state guide presents these forms as equivalent ways to use Compose MutableState:
val state = remember { mutableStateOf(...) }
var value by remember { mutableStateOf(...) }
val (value, setValue) =
remember { mutableStateOf(...) }
:contentReference[oaicite:26]{index=26}
Be Careful with Mutable Collections
Code such as:
val items = remember { mutableStateOf( mutableListOf<String>() ) }
items.value.add("A")
can be problematic because changes inside a normal mutable collection are not necessarily observable by Compose.
Google’s state documentation warns that mutable objects such as ArrayList and mutableListOf() are not automatically observable by Compose and can result in stale UI. :contentReference[oaicite:27]{index=27}
For example, replace the state value with a new immutable list:
var items by remember { mutableStateOf( listOf<String>() ) }
items = items + "A"
Should a ViewModel Use mutableStateOf or StateFlow?
Both approaches can be valid depending on the application architecture.
mutableStateOf integrates directly with Compose, while StateFlow is often useful for ViewModel-driven asynchronous state and broader unidirectional data-flow architectures.
You do not need to change your state architecture simply to fix this unresolved-reference error.
First verify:
- The import
- Compose Runtime
- The module configuration
- Gradle Sync
Minimal mutableStateOf Example
import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember
@Composable
fun Sample() {
val state = remember {
mutableStateOf(false)
}
}
Minimal Delegated-State Example
import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue
@Composable
fun Sample() {
var enabled by remember {
mutableStateOf(false)
}
Button(
onClick = {
enabled = !enabled
}
) {
Text(
if (enabled) "ON" else "OFF"
)
}
}
Fastest Troubleshooting Order
- Check for
import androidx.compose.runtime.mutableStateOf. - If using
remember, verify its import too. - If using
by, verifygetValueandsetValue. - Confirm that Compose is enabled for the module.
- Confirm that Compose Runtime is in the dependency graph.
- Check the Compose BOM configuration.
- Run Gradle Sync.
- Run
./gradlew assembleDebugto inspect the real compiler result.
If the Error Still Occurs
Check all of the following:
androidx.compose.runtime.mutableStateOfis imported.- The import was not accidentally removed.
- Compose Runtime exists in the dependency graph.
- The Compose BOM is configured correctly.
- The module has Compose enabled.
- The source code was not moved into a module without Compose dependencies.
- Gradle Sync completes successfully.
- No dependency-resolution error occurs first.
- You did not import only
MutableStatewithoutmutableStateOf. - You are not confusing
mutableStateOfwithmutableIntStateOfor another primitive state API. - Property-delegate imports exist when using
by. - The command-line Gradle build shows the same error.
Summary
Jetpack Compose “Unresolved reference: mutableStateOf” usually means that the Kotlin compiler cannot resolve Compose Runtime’s mutableStateOf function.
Start by checking:
import androidx.compose.runtime.mutableStateOf
For common delegated Compose state, use:
import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue
and:
var count by remember { mutableStateOf(0) }
Google’s current Compose documentation states that mutableStateOf creates an observable MutableState integrated with the Compose runtime, and changing its value schedules recomposition for Composables that read it. :contentReference[oaicite:28]{index=28}
When creating state inside a Composable, remember { mutableStateOf(...) } is the standard pattern because remember keeps the state object across recompositions. :contentReference[oaicite:29]{index=29}
If the import alone does not fix the error, check Compose Runtime dependencies, the Compose BOM, the module’s buildFeatures.compose configuration, and Gradle Sync in that order.
