本文介绍了Jetpack compose 更新到 1.0.0-rc01 后无法预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这仅在我更新到 1.0.0-rc01 时发生在我身上.它说:

this happened to me only when I updated to 1.0.0-rc01.it says:

找不到以下类:- androidx.compose.ui.tooling.preview.ComposeViewAdapter(修复构建路径、编辑 XML、创建类)

我的代码:

@Composable
@Preview
fun CenterProgress(){
    Box(
        modifier= Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ){
        CircularProgressIndicator(strokeWidth = 3.dp)
    }
}

推荐答案

更新:Android Studio Bumblebee 不再需要此内容 |2021.1.1 Canary 6Android Gradle 插件 7.1.0-alpha06.注意:Canary 4 已经修复了这个问题,但需要一个损坏的 AGP 版本.现在也解决了.

Update: This is no longer needed with Android Studio Bumblebee | 2021.1.1 Canary 6 and Android Gradle Plugin 7.1.0-alpha06. Note: Canary 4 already fixed this issue but required a broken version of AGP. This is now also resolved.

除了上面的答案:这里是如何在 gradle 中强制使用 ui-tooling 版本:

In addition to the above answers: here is how to force the ui-tooling version in gradle:

implementation("androidx.compose.ui:ui-tooling:$compose_version") {
    version {
        // TODO: Remove this when Android Studio has become compatible again
        // Android Studio Bumblebee | 2021.1.1 Canary 3 is not compatible with module ui-tooling 1.0.0-rc01 or higher.
        // The Run Configuration for Composable Previews that Android Studio makes expects a PreviewActivity class
        // in the `androidx.compose.ui.tooling.preview` package, but it was moved in 1.0.0-rc01, and thus causes error:
        // "androidx.compose.ui.tooling.preview.PreviewActivity is not an Activity subclass or alias".
        // For more, see: https://stackoverflow.com/questions/68224361/jetpack-compose-cant-preview-after-updating-to-1-0-0-rc01
        strictly("1.0.0-beta09")
    }
}

这篇关于Jetpack compose 更新到 1.0.0-rc01 后无法预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 10:17