Ankush
Ankush

Reputation: 1978

androidx.compose.ui.tooling.preview.PreviewActivity does not exist - Jetpack Compose

I have been dealing with this issue where while running a preview of a composable, I recieve and error

Error while executing: am start -n "com.site.app/androidx.compose.ui.tooling.preview.PreviewActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER --es composable com.site.app.ui.MainActivity.MainAppPreview
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.site.app/androidx.compose.ui.tooling.preview.PreviewActivity (has extras) }
Error type 3
Error: Activity class {com.site.app/androidx.compose.ui.tooling.preview.PreviewActivity} does not exist.

Error while Launching activity
Failed to launch an application on all devices

I checked the package structure and the PreviewActivity does not exist at androidx.compose.ui.tooling.preview but it's avaialble at androidx.compose.ui.tooling.

I found a similar question but it's old and basically invalidating cache did not resolve the problem for me.

I am targetting

It seems to me that the problem lies somewhere around the gradle versioning as the path at which it is checking for PreviewActivity is itself wrong. I tested the behaviour on an older project and things were fine even the path was also correct.

Upvotes: 2

Views: 1982

Answers (2)

Ankush
Ankush

Reputation: 1978

As I suspected, the issue was with the compose version. During the course of development compose version 1.5.4 came in, which resolved the issue of PreviewActivity being referenced from androidx.compose.ui.tooling.preview

Upvotes: 2

Chirag Thummar
Chirag Thummar

Reputation: 3262

I was also facing the same issue with the below library dependency

implementation "androidx.compose.ui:ui-tooling-preview:1.3.3"

Then I removed the preview library and used its root library and it's generating a preview for me.

now I am using the below dependency for my project.

implementation "androidx.compose.ui:ui-tooling:1.3.3"

Upvotes: 4

Related Questions