Android Studio 未找到类定义错误:无法初始化类androidx,自定义视图,池化容器,池化容器

wpcxdonn  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(265)

使用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)
    ...

如何提供缺少的androidx.customview.poolingcontainer.R$id

mwngjboj

mwngjboj1#

正如阅读源代码时所发现的那样,这需要customview-poolingcontainer

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

本以为它包含在customview中,但事实并非如此。这会使预览表现正常。
Here正在解释为什么会这样:

池化容器库

这添加了ComposeRecyclerView都依赖的androidx.customview:customview-poolingcontainer工件,AbstractComposeViewRecyclerView通过该工件发现彼此,并就Compose视图何时应处置其组合进行通信。
该机制独立于ComposeRecyclerView,并且可用于任何回收容器或具有应在回收过程中保留的重资源的子容器。
Relnote:“添加一个新的PoolingContainer库,该库允许侦听在视图层次结构之外管理其子级的容器的释放事件。稍后将添加此库作为ComposeRecyclerView的依赖项“
错误编号:196371929

相关问题