2

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

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.