如何解决Android Compose无法在android studio“渲染问题”中预览可组合功能
@Preview
@Composable
fun StartingConversationInstructions() {
Column {
Text(stringResource(id = R.string.remember))
}
}
java.lang.NoSuchMethodError: 'androidx.compose.runtime.Slottable
androidx.compose.runtime.Composer.getSlottable()' at
androidx.ui.tooling.InspectableKt.Inspectable(Inspectable.kt:63) at
androidx.ui.tooling.preview.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt:357) at
androidx.ui.tooling.preview.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt:-1) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:-1) at
androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188) at
androidx.ui.tooling.preview.ComposeViewAdapter.WrapPreview(ComposeViewAdapter.kt:356) at
androidx.ui.tooling.preview.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.kt:-1) at
androidx.ui.tooling.preview.ComposeViewAdapter$init$1.invoke(ComposeViewAdapter.kt:397) at
androidx.ui.tooling.preview.ComposeViewAdapter$init$1.invoke(ComposeViewAdapter.kt:-1) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:-1) at
androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188) at
androidx.compose.ui.platform.AmbientsKt.ProvideCommonAmbients(Ambients.kt:274) at
androidx.compose.ui.platform.AndroidambientsKt$ProvideAndroidambients$3.invoke(Androidambients.kt:176) at
androidx.compose.ui.platform.AndroidambientsKt$ProvideAndroidambients$3.invoke(Androidambients.kt:-1) at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:-1) at
androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188) at
androidx.compose.ui.platform.AndroidambientsKt.ProvideAndroidambients(Androidambients.kt:168) at
androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.kt:251) at
androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.kt:-1) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:-1) at
androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188) at
androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.kt:250) at
androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.kt:-1) at
.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146) at
androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:-1) at
androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:2904) at
androidx.compose.runtime.Composer.composeInitial(Composer.kt:2070) at
androidx.compose.runtime.recomposer.composeInitial$runtime_release(recomposer.kt:353) at
androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:109) at
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt:235) at
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt:-1) at
androidx.compose.ui.platform.AndroidComposeView.setonViewTreeOwnersAvailable(AndroidComposeView.kt:545)
at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.kt:226) at
androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.kt:275) at
androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354) at
androidx.lifecycle.LifecycleRegistry.addobserver(LifecycleRegistry.java:196) at
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt:233) at
androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt:-1) at
androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.kt:610) at
android.view.View.dispatchAttachedToWindow(View.java:20479) at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3489) at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496) at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496) at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496) at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496) at
android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:44) copy stack to clipboard
Tip: Try to refresh the layout.
我使用的是 android studio 版本:Android Studio 北极狐 | 2020.3.1 金丝雀 4
和 Android Compose 版本:1.0.0-alpha09
我认为这是导致问题的原因,因为您可以在此版本的 changes
从公共 API 中删除了 Slottable、SlotReader 和 SlotWriter。这些之前被标记为 InternalComposeAPI。现在它们位于 compose 模块的内部。
解决方法
在您的依赖项中,更改
implementation "androidx.ui:ui-tooling:$compose_version"
到
implementation "androidx.compose.ui:ui-tooling:$compose_version"
那行得通吗?
,正如@author 在他的 comment 中所述,有两个相同的注释:
import androidx.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.Preview
第二个对我有用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。