Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Compose preview shows a render problem in the issues panel

Errorjava.lang.NoSuchFieldError: view_tree_saved_state_registry_owner

Short answer

The preview runs your composable inside Android Studio, not on a device, so some libraries must be on the debug classpath and some code cannot run there. Read the exact exception in the issues panel: each one maps to a debugImplementation dependency, and a ViewModel failure means the screen needs a state-only composable.

  • Applies to Android Studio (current stable), Compose BOM 2026.x, Android Gradle Plugin 8.x and 9.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Open the preview's issues panel and copy the first exception line. The class or field name in it decides which cause applies.

    # In Android Studio: open the Design tab of the file, click the red 'Render problem' link, read the first exception line
  2. 2Match what you see, then jump to its fix

    1. 1NoSuchFieldError: view_tree_saved_state_registry_owner, or ClassNotFoundException: androidx.savedstate.R$idThe saved-state libraries are missing from the debug classpathFix
    2. 2NoSuchFieldError: view_tree_lifecycle_ownerThe lifecycle runtime library is missingFix
    3. 3NoClassDefFoundError for androidx.customview.poolingcontainer.PoolingContainer or PoolingContainerListenerThe pooling container library is missingFix
    4. 4Failed to instantiate a ViewModel in the problems paneThe previewed composable creates a ViewModelFix

What does the error look like?

  • java.lang.NoSuchFieldError: view_tree_saved_state_registry_owner
  • java.lang.ClassNotFoundException: androidx.savedstate.R$id
  • java.lang.NoSuchFieldError: view_tree_lifecycle_owner
  • java.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.PoolingContainer
  • Failed to instantiate a ViewModel

Cause 1 of 4

The saved-state libraries are missing from the debug classpath

1Check

Check whether the module already has the lifecycle saved-state artifact.

grep -rn "lifecycle-viewmodel-savedstate" --include=*.gradle --include=*.kts --include=*.toml .

2Fix

Add a debugImplementation dependency on androidx.lifecycle:lifecycle-viewmodel-savedstate to the module.

dependencies {
    debugImplementation("androidx.lifecycle:lifecycle-viewmodel-savedstate:<version>")
}

3Verify

Sync, then use Build and Refresh in the preview.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 4

The lifecycle runtime library is missing

1Check

Look for the lifecycle runtime artifact in the module's dependencies.

grep -rn "lifecycle-runtime" --include=*.gradle --include=*.kts --include=*.toml .

2Fix

Add a debugImplementation dependency on androidx.lifecycle:lifecycle-runtime.

dependencies {
    debugImplementation("androidx.lifecycle:lifecycle-runtime:<version>")
}

3Verify

Sync and refresh the preview; the field error should be gone.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 4

The pooling container library is missing

1Check

Search the module for the customview-poolingcontainer artifact.

grep -rn "customview-poolingcontainer" --include=*.gradle --include=*.kts --include=*.toml .

2Fix

Add a debugImplementation dependency on androidx.customview:customview-poolingcontainer.

dependencies {
    debugImplementation("androidx.customview:customview-poolingcontainer:<version>")
}

3Verify

Sync and refresh the preview.

./gradlew :app:assembleDebug

Confirmed by developer.android.com

Did this fix it?

Cause 4 of 4

The previewed composable creates a ViewModel

1Check

Find the composable under @Preview and see whether it calls viewModel() or receives a Hilt ViewModel as a parameter.

grep -rn "viewModel()\|hiltViewModel()" app/src/main

2Fix

Previews cannot build repositories or an injected dependency graph. Split the screen into one composable that gets the ViewModel and a second that takes plain state parameters, and preview the second one with sample data.

@Composable
fun AuthorScreen(viewModel: AuthorViewModel = viewModel()) {
    AuthorScreen(name = viewModel.authorName)
}

@Composable
fun AuthorScreen(name: String) { /* UI only */ }

@Preview
@Composable
fun AuthorScreenPreview() { AuthorScreen(name = "Sample") }

3Verify

The preview renders without the ViewModel.

# Refresh the preview in the Design tab

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Keep screen UI in composables that take state and events as parameters; only the top wrapper touches a ViewModel.
  • Remember previews have no network or file access, so use sample data.
  • Use LocalInspectionMode to show placeholder content where a real data source cannot run in a preview.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android app crashes because the Apache HTTP classes are missing

java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;

From Android 9 the Apache HTTP client is no longer on the default classpath, so code or a library that still uses org.apache.http fails at runtime.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.