Status Update
Comments
[Deleted User] <[Deleted User]> #2
so...@google.com <so...@google.com>
di...@google.com <di...@google.com>
el...@airbnb.com <el...@airbnb.com> #3
Our team is also running into this because we use kotlin reflection to set up mock data for previews.
Can you suggest any workaround that we can apply locally to make layout lib include kotlin reflect until it is officially fixed? We are obviously including it as a build dependency but the layout lib preview doesn't pick it up for some reason.
el...@airbnb.com <el...@airbnb.com> #4
I do not see this issue in Electric Eel Beta 4, but I do see it in Flamingo Canary 6.
am...@google.com <am...@google.com> #5
I do not see this issue in Electric Eel Beta 4, but I do see it in Flamingo Canary 6.
Is it with the very same project? I'm trying to rule out whether this is related to specific library/compiler versions.
Thanks!
el...@airbnb.com <el...@airbnb.com> #6
Yes, that was with the same project. I can double check with the latest versions of each IDE and get back to you though.
el...@airbnb.com <el...@airbnb.com> #7
Correction: I was either mistaken before, or behavior has changed, but I am now getting the KotlinReflectionNotSupportedError
issue for IDE compose previews in both EE Beta 5 and Flamingo Canary 8.
Kotlin 1.6.21 AGP 7.3
lu...@gmail.com <lu...@gmail.com> #8
na...@codigo.co <na...@codigo.co> #9
am...@google.com <am...@google.com> #10
Diego, this looks to be the same problem as
di...@google.com <di...@google.com> #11
This looks to be the same as
di...@google.com <di...@google.com> #12
I'm pretty sure the failure is in locating kotlin.reflect.jvm.internal.ReflectionFactoryImpl
in
That Class.forName
should redirect to the "renamed" version that we move in the classpath to the layoutlib.internal so it loads the correct JVM version in
di...@google.com <di...@google.com> #13
The fix for this will be in a future canary of Flamingo.
ja...@gmail.com <ja...@gmail.com> #14
I'm on Flamingo 2022.2.1 Patch 1 and this isn't working quite right...Preview does not report any errors specific to Kotlin reflection anymore and will generate a preview, but it's as if the kotlin-reflect library was never loaded. For instance, given sealed class Foo
, calling Foo::class.isSealed
in a Preview Composable returns false, yet returns true when called in a Composable running on a physical device.
el...@airbnb.com <el...@airbnb.com> #15
I noticed this as well, and created this issue
ri...@dice.fm <ri...@dice.fm> #16
pa...@google.com <pa...@google.com>
am...@google.com <am...@google.com> #17
Reopening as this doesn't seem to be fixed, according to multiple reports.
jo...@tmediatech.com <jo...@tmediatech.com> #18
I presume this is related, if not I can open a new issue.
For context, BackgroundUploadState
can be any sealed class or interface and the subclasses can be data object
s, object
s, or class
es and it makes no difference.
With this in a PreviewParameterProvider: BackgroundUploadState::class.sealedSubclasses
, I get the following Render Issue error:
java.lang.IndexOutOfBoundsException: Sequence doesn't contain element at index 0.
at _layoutlib_._internal_.kotlin.sequences.SequencesKt___SequencesKt$elementAt$1.invoke(_Sequences.kt:35)
at _layoutlib_._internal_.kotlin.sequences.SequencesKt___SequencesKt$elementAt$1.invoke(_Sequences.kt:35)
at _layoutlib_._internal_.kotlin.sequences.SequencesKt___SequencesKt.elementAtOrElse(_Sequences.kt:55)
at _layoutlib_._internal_.kotlin.sequences.SequencesKt___SequencesKt.elementAt(_Sequences.kt:35)
at androidx.compose.ui.tooling.PreviewUtils_androidKt.getPreviewProviderParameters(PreviewUtils.android.kt:62)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1$composable$1$1.invoke(ComposeViewAdapter.android.kt:508)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1$composable$1$1.invoke(ComposeViewAdapter.android.kt:502)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1.invoke(ComposeViewAdapter.android.kt:539)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3$1.invoke(ComposeViewAdapter.android.kt:497)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
at androidx.compose.ui.tooling.InspectableKt.Inspectable(Inspectable.android.kt:61)
at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.android.kt:444)
at androidx.compose.ui.tooling.ComposeViewAdapter$WrapPreview$1.invoke(ComposeViewAdapter.android.kt:443)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
at androidx.compose.ui.tooling.ComposeViewAdapter.WrapPreview(ComposeViewAdapter.android.kt:438)
at androidx.compose.ui.tooling.ComposeViewAdapter.access$WrapPreview(ComposeViewAdapter.android.kt:124)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.android.kt:497)
at androidx.compose.ui.tooling.ComposeViewAdapter$init$3.invoke(ComposeViewAdapter.android.kt:494)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:441)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:259)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:258)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:216)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:132)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:131)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:380)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:121)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:155)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:154)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:401)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:154)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:133)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:109)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:97)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3593)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3520)
at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:743)
at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:1114)
at androidx.compose.runtime.CompositionImpl.composeInitial(Composition.kt:649)
at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:635)
at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:124)
at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1597)
at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:124)
at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:180)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.jvm.kt:320)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.jvm.kt:198)
at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:131)
at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:124)
at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1678)
at android.view.View.dispatchAttachedToWindow(View.java:21980)
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:51)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:372)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:454)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:120)
at com.android.tools.rendering.RenderTask.createRenderSession(RenderTask.java:779)
at com.android.tools.rendering.RenderTask.lambda$inflate$6(RenderTask.java:927)
at com.android.tools.rendering.RenderExecutor$runAsyncActionWithTimeout$3.run(RenderExecutor.kt:204)
at com.android.tools.rendering.RenderExecutor$PriorityRunnable.run(RenderExecutor.kt:321)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
di...@google.com <di...@google.com>
di...@google.com <di...@google.com>
ub...@gmail.com <ub...@gmail.com> #19
Great to see this is fixed, which Android Studio release will have the fix included? Will the fix make its way into 2024.2.2?
di...@google.com <di...@google.com> #20
No, unfortunately the fix will not be available for 2024.2.2. The next Meerkat Canary will have the fix. It should also be available in the Nightly build already.
an...@google.com <an...@google.com> #21
Thank you for your patience while our engineering team worked to resolve this issue. A fix for this issue is now available in:
- Android Studio Meerkat | 2024.3.1 Canary 3
- Android Gradle Plugin 8.9.0-alpha03
We encourage you to try the latest update.
If you notice further issues or have questions, please file a new bug report.
Thank you for taking the time to submit feedback — we really appreciate it!
Description
In some cases I'm getting this error when the compose preview is being generated:
In this case the next line in the stacktrace is our own code, basically custom dependency injection which is using reflection: val foo = kClass.constructors ...
Is there something the preview mechanism can do here so that part runs also? It's an other question if it makes sense to have runtime DI for previews. I'd like to mock out the dependencies, but there is a:
in the composable function which is not clear yet to us how to exchange with a test object.
We're working on it (also any feedback is welcome), but maybe the above error can be also improved on the Compose Preview side.