I have defined the Kotlin reflection dependency in my Gradle file as follows:
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
Within the App, reflection works just fine. However, when I use reflection within a Composable preview:
@Composable
@Preview
fun MyComposablePreviewUsingReflection() {
val foo = SomeClass::class.sealedSubclasses.size
}
I get the kotlin.jvm.KotlinReflectionNotSupportedError
. When I build the App and use reflection in a normal Composable (i.e., not a preview), reflection works just fine.
Is there a way to get reflection working in a Compose preview?
This problem will be fixed in Android Studio Flamingo. https://issuetracker.google.com/issues/240601093