Hello guys :android-wave: have you ever been in a ...
# compose
n
Hello guys 👋 have you ever been in a situation where the compose preview in android studio won’t show up when you have
kotlin reflect
related codes in your composables? I’m trying to use a form validation library for compose which uses kotlin reflect under the hood and it makes the preview builds to be fail ☹️ I get the following stack trace from preview issues panel
Copy code
java.lang.ClassCastException: class _layoutlib_._internal_.kotlin.jvm.internal.ClassReference cannot be cast to class _layoutlib_._internal_.kotlin.reflect.jvm.internal.KClassImpl (_layoutlib_._internal_.kotlin.jvm.internal.ClassReference and _layoutlib_._internal_.kotlin.reflect.jvm.internal.KClassImpl are in unnamed module of loader org.jetbrains.android.uipreview.ModuleClassLoader @447dcf4d)
	at _layoutlib_._internal_.kotlin.reflect.full.KClasses.getPrimaryConstructor(KClasses.kt:36)
	at me.naingaungluu.formconductor.FormImpl.constructorRequirementSatisfied(FormImpl.kt:135)
	at me.naingaungluu.formconductor.FormImpl.<init>(FormImpl.kt:46)
	at me.naingaungluu.formconductor.composeui.FormComposablesKt.form(FormComposables.kt:36)
	at com.memoto.mobileapp.feature.booking.checkin.guests.ComposableSingletons$CheckInGuestFormScreenKt$lambda-2$1.invoke(CheckInGuestFormScreen.kt:44)
	at com.memoto.mobileapp.feature.booking.checkin.guests.ComposableSingletons$CheckInGuestFormScreenKt$lambda-2$1.invoke(CheckInGuestFormScreen.kt:43)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:116)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.foundation.lazy.LazyListScopeImpl$item$3.invoke(LazyListScopeImpl.kt:54)
	at androidx.compose.foundation.lazy.LazyListScopeImpl$item$3.invoke(LazyListScopeImpl.kt:54)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:135)
	at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
	at androidx.compose.foundation.lazy.LazyListItemsSnapshot.Item(LazyListItemProviderImpl.kt:99)
	at androidx.compose.foundation.lazy.LazyListItemProviderImpl.Item(LazyListItemProviderImpl.kt:126)
	at ......
🧵 2
j
@Chris Sinco [G]
c
Hmm @Naing Aung Luu can you provide a sample snippet or project to help us repro?
n
Copy code
data class DummyForm(
    val emailAddress: String = ""
)

@Composable
fun ErroneousComposable() {
    val primaryConstructor = (DummyForm::class as KClass<DummyForm>).primaryConstructor
}
trying to use kotlin reflection inside any composable would make the preview fail somehow
@Chris Sinco [G] please let me know if you need something else!
c
Thanks - it looks like reflection is not supported in Preview, but we’re working on adding support now