How to fix preview for Jetpack Compose?

Viewed 75

I try to use Jetpack Compose in my existing project the problem is if I include @Preview annotation it doesn't show me anything, just this

enter image description here

There is my code

@Preview
@Composable
fun test() {
    Text(text = "HELLO")
}

What am I missing here?

UPD

I assume this issue somehow related to that fact that I added Compose to existing project, as if I try to create the project from the scratch it works perfectly.

In addition I would like to add the error screenshot

enter image description here

2 Answers

Make sure you have the following dependencies in your project

debugImplementation "androidx.compose.ui:ui-tooling:1.2.1"
implementation "androidx.compose.ui:ui-tooling-preview:1.2.1"

Plus you are on the Android Gradle Plugin version that matches with the version of Android Studio you are using.

Among adding these:

debugImplementation "androidx.compose.ui:ui-tooling:1.2.1"
implementation "androidx.compose.ui:ui-tooling-preview:1.2.1"

Add these too:

debugImplementation "androidx.customview:customview:1.2.0-alpha01"
debugImplementation "androidx.customview:customview-poolingcontainer:1.0.0"

Worked for me with Android Studio Chipmunk | 2021.2.1 Patch 2,
AGP 7.2.2,
ComposeCompiler 1.3.1,
Compose 1.2.1

[Source: https://issuetracker.google.com/issues/227767363#comment2]

Related