Reputation: 3008
I updated my compose and kotlinCompilerExtensionVersion to 1.0.0-rc02
from beta09
, Kotlin version to 1.5.21
, Gradle version to 7.1
and Gradle plugin version to 7.1.0-alpha04
Ever since - on trying to run MyScreen
- I'm getting this error:
androidx.compose.ui.tooling.preview.PreviewActivity is not an activity subclass or alias
I am not able to resolve this. How do I resolve this?
Upvotes: 20
Views: 8510
Reputation: 121
I am using Compose 1.0, Kotlin 1.5.10 and Android Studio 2020.3.1, and I run into the same problem on most of my previews (not on others).
On the top bar menu, clicking on "Edit configurations" and manually creating a new configuration with the same parameters as those in the invalid configuration with warning (" androidx.compose.ui.tooling.PreviewActivity is not an Activity subclass or alias")
did the trick for me.
Upvotes: 12
Reputation: 3447
I'm experiencing this error using Bumblebee (AKA, 2021.1.1) Canary 6, 7, and 8, using compose version 1.0.0, 1.0.1, and 1.1.0-alpha01. I've just raised a bug on the Studio issue tracker:
https://issuetracker.google.com/issues/196248459
To quote myself:
It seems clear this is a "left hand doesn't know what right hand is doing" thing, because
PreviewActivity
is not in that package, but ratherandroidx.compose.ui.tooling
– it hasn't been inandroid.compose.ui.tooling.preview
since compose 1.0.0-beta09.
I was able to get previews working again by clearing off all the preview run configurations. Here were my steps:
-
button to remove all the collectionsOk
Apparently AS was caching "junk" in the temporary run configurations it was creating every time I launched a preview. The "junk" was valid for earlier versions of AS, but broke later versions. Clearing out this cache got me working again.
Upvotes: 8
Reputation: 334
Updating the compose_version
to 1.0.1
, and kotlin-gradle-plugin
to 1.5.21
fixes the issue if the versions used are lower than mentioned here.
Upvotes: 0
Reputation: 3008
The thing that worked for me was downgrading the ui-tooling version to beta09, i.e using this dependency for ui-tooling:
implementation "androidx.compose.ui:ui-tooling:1.0.0-beta09"
Upvotes: 0
Reputation: 705
I've got the same error with Compose 1.0.0
and Kotlin 1.5.10
(which is recommended).
I fixed these with adding the following dependence debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
in my gradle file.
Don't forget to set the version of the dependence to your current compose version.
After a rebuild and reload of the preview everything works fine for me.
The Preview of the example looks like this:
package com.example.compose.basics.ui
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import de.db.dbs.travio.compose.basics.themeing.ComposeBasicsTheme
@Preview
@Composable
fun ScreenContent() {
ComposeBasicsTheme {
Card(modifier = Modifier
.padding(8.dp)
.shadow(8.dp, RoundedCornerShape(32.dp))
) {
Text(
text = "Hello World!",
modifier = Modifier.padding(16.dp)
)
}
}
}
Upvotes: 4