3

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

Sirop4ik
  • 4,543
  • 2
  • 54
  • 121

3 Answers3

2

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]

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
1

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.

Ben Trengrove
  • 8,191
  • 3
  • 40
  • 58
  • Added UPD in the question. And I double checked I have the related dependences in the gradle. – Sirop4ik Sep 05 '22 at 01:09
  • I have these dependencies and still have the same issue. `Android Studio Chipmunk | 2021.2.1 Patch 2`, `AGP 7.2.2`, `ComposeCompiler 1.3.1`, `Compose 1.2.1`, A fully compose project – Dr.jacky Sep 12 '22 at 13:14
0

I was able to make it work by replacing

debugImplementation("androidx.compose.ui:ui-tooling")

With

implementation("androidx.compose.ui:ui-tooling")

It's not optimal since the library will be included in release builds but it works as a temporal fix.

Martin U
  • 56
  • 2