1

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?

mexes
  • 117
  • 7

1 Answers1

0

This problem will be fixed in Android Studio Flamingo. https://issuetracker.google.com/issues/240601093

ntsk
  • 16
  • 1
  • As of Flamingo 2022.2.1 Patch 1, it is "fixed" but doesn't appear to be functional, at least for sealed classes. `isSealed` returns false, and `sealedSubclasses` is always empty. – Jason Robinson May 10 '23 at 03:40