Issue
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?
Solution
As it turned out when reading the sources, this needs the customview-poolingcontainer:
debugImplementation "androidx.customview:customview-poolingcontainer:1.0.0-rc01"
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 anandroidx.customview:customview-poolingcontainerartifact that is depended on by bothComposeandRecyclerView, through whichAbstractComposeViewandRecyclerViewdiscover each other and communicate about when theComposeview should dispose its composition.
This mechanism is independent of bothComposeandRecyclerView, 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 ofComposeandRecyclerView"
Bug: 196371929
Answered By - Martin Zeitler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.