使用Jetpack编写UI工具1.2.0-rc01
和编写编译器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
}
IDE无法显示@Preview
;它将失败,并显示:
java.lang.NoClassDefFoundError: Could not initialize class androidx.customview.poolingcontainer.PoolingContainer
at androidx.compose.ui.platform.ViewCompositionStrategy$DisposeOnDetachedFromWindowOrReleasedFromPool.installFor(ViewCompositionStrategy.android.kt:97)
...
真正的原因是别的:
java.lang.ClassNotFoundException: androidx.customview.poolingcontainer.R$id
at com.android.tools.idea.rendering.classloading.loaders.DelegatingClassLoader.findClass(DelegatingClassLoader.kt:81)
...
1条答案
按热度按时间mwngjboj1#
正如阅读源代码时所发现的那样,这需要
customview-poolingcontainer
:本以为它包含在
customview
中,但事实并非如此。这会使预览表现正常。Here正在解释为什么会这样:
池化容器库
这添加了
Compose
和RecyclerView
都依赖的androidx.customview:customview-poolingcontainer
工件,AbstractComposeView
和RecyclerView
通过该工件发现彼此,并就Compose
视图何时应处置其组合进行通信。该机制独立于
Compose
和RecyclerView
,并且可用于任何回收容器或具有应在回收过程中保留的重资源的子容器。Relnote:“添加一个新的PoolingContainer库,该库允许侦听在视图层次结构之外管理其子级的容器的释放事件。稍后将添加此库作为
Compose
和RecyclerView
的依赖项“错误编号:196371929