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?

1 Answer 1

0

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

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. May 10 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.