Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.PoolingContainer

With Jetpack Compose UI Tooling 1.2.0-rc01 and Compose Compiler 1.2.0;

android {
    composeOptions {
        kotlinCompilerExtensionVersion "1.2.0"
    }
}
dependencies {
    debugImplementation "androidx.compose.ui:ui-tooling:1.2.0-rc01"
    debugImplementation "androidx.customview:customview:1.1.0" // being pulled in by another dependency
    debugImplementation "androidx.customview:customview:1.2.0-alpha01" // also tried the latest version
}

The IDE cannot display the @Preview; it fails with:

java.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.PoolingContainer
    at androidx.compose.ui.platform.ViewCompositionStrategy$DisposeOnDetachedFromWindowOrReleasedFromPool.installFor(ViewCompositionStrategy.android.kt:97)
    ...

The actual cause is something else:

java.lang.ClassNotFoundException: androidx.customview.poolingcontainer.R$id
    at com.android.tools.idea.rendering.classloading.loaders.DelegatingClassLoader.findClass(DelegatingClassLoader.kt:81)
    ...

How can I provide the missing androidx.customview.poolingcontainer.R$id?

like image 257
Martin Zeitler Avatar asked Jun 15 '26 10:06

Martin Zeitler


1 Answers

As it turned out when reading the sources, this needs the customview-poolingcontainer:

debugImplementation "androidx.customview:customview-poolingcontainer:1.0.0"

Thought it was included in customview, but it's not. This makes the preview behave.


Here it is being explained why it's like that:

PoolingContainer library

This adds an androidx.customview:customview-poolingcontainer artifact that is depended on by both Compose and RecyclerView, through which AbstractComposeView and RecyclerView discover each other and communicate about when the Compose view should dispose its composition.

This mechanism is independent of both Compose and RecyclerView, and could be used for any recycling container or child with heavy resources that should be retained across recycling.

Relnote: "Add a new PoolingContainer library that allows for listening to dispose events of a container that manages its children outside the View hierarchy. This will later be added as a dependency of Compose and RecyclerView"

Bug: 196371929

like image 186
Martin Zeitler Avatar answered Jun 17 '26 06:06

Martin Zeitler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!