https://kotlinlang.org logo
#compose
Title
# compose
c

Cyril Find

01/20/2021, 9:35 AM
Hi, I have a preview composable defined like this:
Copy code
@Preview
@Composable
fun PostHeader_Preview() {
    MyAppTheme {
        PostHeader(Post.PLACEHOLDER)
    }
}
that has a render problem that looks like this:
java.lang.NoSuchMethodException: com.example.myapp.components.PostHeaderKt.PostHeader_Preview
(full stacktrace in thread 🧵 ) I have no idea how to fox that since the method actually exists, what can I do ?
Copy code
java.lang.NoSuchMethodException: com.unique.powder.components.PostHeaderKt.PostHeader_Preview
	at androidx.compose.ui.tooling.preview.PreviewUtilsKt.findComposableMethod(PreviewUtils.kt:72)
	at androidx.compose.ui.tooling.preview.PreviewUtilsKt.invokeComposableViaReflection(PreviewUtils.kt:175)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$init$3$2$composable$1.invoke(ComposeViewAdapter.kt:437)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$init$3$2$composable$1.invoke(ComposeViewAdapter.kt)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$init$3$2.invoke(ComposeViewAdapter.kt:471)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$init$3$2.invoke(ComposeViewAdapter.kt)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt)
	at androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188)
	at androidx.compose.ui.tooling.InspectableKt.Inspectable(Inspectable.kt:65)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt:384)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.kt)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt)
	at androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter.WrapPreview(ComposeViewAdapter.kt:383)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.kt)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt:430)
	at androidx.compose.ui.tooling.preview.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.kt)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt)
	at androidx.compose.ui.platform.ComposeView.Content(ComposeView.kt:293)
	at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.kt:161)
	at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.kt)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt)
	at androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188)
	at androidx.compose.ui.platform.AmbientsKt.ProvideCommonAmbients(Ambients.kt:276)
	at androidx.compose.ui.platform.AndroidAmbientsKt$ProvideAndroidAmbients$3.invoke(AndroidAmbients.kt:176)
	at androidx.compose.ui.platform.AndroidAmbientsKt$ProvideAndroidAmbients$3.invoke(AndroidAmbients.kt)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt)
	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$3.invoke(Wrapper.kt:261)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.kt)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt)
	at androidx.compose.runtime.AmbientKt.Providers(Ambient.kt:188)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.kt:260)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.kt)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt:146)
	at androidx.compose.runtime.internal.ComposableLambda.invoke(ComposableLambda.kt)
	at androidx.compose.runtime.ComposerKt.invokeComposable(Composer.kt:2906)
	at androidx.compose.runtime.Composer.composeInitial(Composer.kt:2046)
	at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:566)
	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:109)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt:243)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt)
	at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.kt:548)
	at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.kt:234)
	at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.kt:285)
	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:241)
	at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.kt)
	at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.kt:617)
	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.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3496)
	at android.view.AttachInfo_Accessor.setAttachInfo(AttachInfo_Accessor.java:44)
	at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:361)
	at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:431)
	at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:141)
	at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:696)
	at com.android.tools.idea.rendering.RenderTask.lambda$inflate$6(RenderTask.java:852)
	at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.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)
j

jim

01/20/2021, 10:23 AM
That error doesn't give us a ton of info to work with, unfortunately. Just throwing some ideas/questions out there: • Are you sure Compose is properly enabled for the module where
PostHeader_Preview
is defined? If Compose is not properly enabled, the Compose Compiler may not be running on the code and thus not generating the code expected by preview. • Are any other preview functions in your app working? Is Compose working in general if you deploy to a device? Are your preview functions in the same module as your other Composable functions? • What version of Compose and what version of AndroidStudio are you using?
c

Cyril Find

01/20/2021, 10:58 AM
Hi thanks a lot for your answer ! So here’s more info: • Yes the app is (almost) not modularized yet, and Compose is enabled • Everything works when launching to a device • some Previews work but only very basic components because it’s been too unstable/slow for me to use them a lot (and also because I haven’t found a way to preview components that use
CoilImage
, which is almost all of them) • I’m using alpha10 and the latest Canary (Android Studio Arctic Fox | 2020.3.1 Canary 4 (#AI-202.7319.50.2031.7049475)
j

JulianK

01/20/2021, 11:55 AM
I remember having a similar exception, didn't have this problem with alpha08 (skipped 09). I think it just disappeared after hitting compile/build/refresh or something (sorry i know this is not very helpful). In general, the preview seems to be not really stable and, more importantly, very slow. It's way faster to just launch the app...
2 Views