Studio BumbleBee "Render Problem" 用于 Compose 预览
Studio BumbleBee "Render Problem" For Compose Preview
我无法在 Studio 中预览任何内容,扩展到像 Text
这样简单的内容。我收到“渲染错误”,显示此堆栈跟踪。
java.lang.NoSuchMethodException: com.<packageName>.Navigation_ComponentsKt.<PreviewName>
at androidx.compose.ui.tooling.CommonPreviewUtils.findComposableMethod(CommonPreviewUtils.kt:78)
at androidx.compose.ui.tooling.CommonPreviewUtils.invokeComposableViaReflection$ui_tooling_release(CommonPreviewUtils.kt:183)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$composable.invoke(ComposeViewAdapter.kt:553)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$composable.invoke(ComposeViewAdapter.kt:551)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:590)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:546)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.tooling.InspectableKt.Inspectable(Inspectable.kt:64)
at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview.invoke(ComposeViewAdapter.kt:495)
at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview.invoke(ComposeViewAdapter.kt:494)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.tooling.ComposeViewAdapter.WrapPreview(ComposeViewAdapter.kt:490)
at androidx.compose.ui.tooling.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.kt:120)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:546)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:543)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:384)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated.invoke(ComposeView.android.kt:228)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated.invoke(ComposeView.android.kt:227)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:148)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals.invoke(AndroidCompositionLocals.android.kt:114)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals.invoke(AndroidCompositionLocals.android.kt:113)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:106)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:162)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:161)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:161)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:144)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:3330)
at androidx.compose.runtime.ComposerImpl$doCompose.invoke(Composer.kt:2577)
at androidx.compose.runtime.ComposerImpl$doCompose.invoke(Composer.kt:2573)
at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(SnapshotState.kt:540)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2566)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:2517)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:476)
at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:727)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:432)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:144)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:135)
at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:727)
at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:135)
at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:187)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:142)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:135)
at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:814)
at android.view.View.dispatchAttachedToWindow(View.java:20751)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:57)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:362)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:714)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate(RenderTask.java:870)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
这似乎是自 Bumblebee Studio 较早更新两到三个版本后才发生的,它引起了很多不适。
我只是在问我是否应该将此作为问题提交到 issuetracker 时才意识到,但现在我已经输入了这个问题,我不会浪费这个辛苦的工作。
开个玩笑,如果有人以前偶然发现过这个问题,并且可能有解决办法,请分享。这是 AGP 或其他组件的已知问题吗?欢迎解决方法。
谢谢
快速修复
使用 Android Studio Artic Fox 2020.3.1。现在稳定并支持 Compose。
我测试了这个 Composable,它工作正常:
@Preview(showBackground = true)
@Composable
fun Greeting(name: String = "") {
Text(text = "Hello $name!")
}
还有什么问题吗?随便评论。
另见
如果需要,您可以启用“交互式和动画预览工具”。它在设置下 -> 启用交互和动画预览工具
这使您无需构建即可立即看到所做的更改。这仅适用于一些基本类型,如字符串和整数
您必须在 build.gradle 文件
中使用 不同版本 的 androidx 工具
implementation "androidx.compose.ui:ui-tooling:1.0.0-rc01"
如果它不起作用,请尝试适合您的其他版本
第 1 步:使用最新版本
implementation "androidx.compose.ui:ui-tooling:1.0.1"
第 2 步:设置 systemUi 和 showBackground
@Preview(showSystemUi = true, showBackground = true)
@Composable
fun ModifierPreview() {
Text("hello world")
}
第三步:运行第一次申请
没有 运行 应用程序显示错误。所以第一次运行应用程序下次点击刷新。
我无法在 Studio 中预览任何内容,扩展到像 Text
这样简单的内容。我收到“渲染错误”,显示此堆栈跟踪。
java.lang.NoSuchMethodException: com.<packageName>.Navigation_ComponentsKt.<PreviewName>
at androidx.compose.ui.tooling.CommonPreviewUtils.findComposableMethod(CommonPreviewUtils.kt:78)
at androidx.compose.ui.tooling.CommonPreviewUtils.invokeComposableViaReflection$ui_tooling_release(CommonPreviewUtils.kt:183)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$composable.invoke(ComposeViewAdapter.kt:553)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$composable.invoke(ComposeViewAdapter.kt:551)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:590)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:546)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.tooling.InspectableKt.Inspectable(Inspectable.kt:64)
at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview.invoke(ComposeViewAdapter.kt:495)
at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview.invoke(ComposeViewAdapter.kt:494)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.tooling.ComposeViewAdapter.WrapPreview(ComposeViewAdapter.kt:490)
at androidx.compose.ui.tooling.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.kt:120)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:546)
at androidx.compose.ui.tooling.ComposeViewAdapter$init.invoke(ComposeViewAdapter.kt:543)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:384)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated.invoke(ComposeView.android.kt:228)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated.invoke(ComposeView.android.kt:227)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:148)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals.invoke(AndroidCompositionLocals.android.kt:114)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals.invoke(AndroidCompositionLocals.android.kt:113)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:106)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:162)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:161)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:215)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:161)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:144)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:3330)
at androidx.compose.runtime.ComposerImpl$doCompose.invoke(Composer.kt:2577)
at androidx.compose.runtime.ComposerImpl$doCompose.invoke(Composer.kt:2573)
at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(SnapshotState.kt:540)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:2566)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:2517)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:476)
at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:727)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:432)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:144)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:135)
at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:727)
at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:135)
at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:187)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:142)
at androidx.compose.ui.platform.WrappedComposition$setContent.invoke(Wrapper.android.kt:135)
at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:814)
at android.view.View.dispatchAttachedToWindow(View.java:20751)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3490)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3497)
at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:57)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:362)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:714)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate(RenderTask.java:870)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
这似乎是自 Bumblebee Studio 较早更新两到三个版本后才发生的,它引起了很多不适。
我只是在问我是否应该将此作为问题提交到 issuetracker 时才意识到,但现在我已经输入了这个问题,我不会浪费这个辛苦的工作。
开个玩笑,如果有人以前偶然发现过这个问题,并且可能有解决办法,请分享。这是 AGP 或其他组件的已知问题吗?欢迎解决方法。
谢谢
快速修复
使用 Android Studio Artic Fox 2020.3.1。现在稳定并支持 Compose。
我测试了这个 Composable,它工作正常:
@Preview(showBackground = true)
@Composable
fun Greeting(name: String = "") {
Text(text = "Hello $name!")
}
还有什么问题吗?随便评论。
另见
如果需要,您可以启用“交互式和动画预览工具”。它在设置下 -> 启用交互和动画预览工具
这使您无需构建即可立即看到所做的更改。这仅适用于一些基本类型,如字符串和整数
您必须在 build.gradle 文件
中使用 不同版本 的 androidx 工具
implementation "androidx.compose.ui:ui-tooling:1.0.0-rc01"
如果它不起作用,请尝试适合您的其他版本
第 1 步:使用最新版本
implementation "androidx.compose.ui:ui-tooling:1.0.1"
第 2 步:设置 systemUi 和 showBackground
@Preview(showSystemUi = true, showBackground = true)
@Composable
fun ModifierPreview() {
Text("hello world")
}
第三步:运行第一次申请
没有 运行 应用程序显示错误。所以第一次运行应用程序下次点击刷新。