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?
For the best experience developing with Jetpack Compose, download and install Android Studio. It includes many smart editor features, such as new project templates and the ability to immediately preview your Compose UI and animations.
Can I use it with Java? Jetpack Compose is Kotlin exclusive. It uses features such as coroutines, and the handling of @Composable annotations is done by a Kotlin compiler. There is no way to get access to these from Java.
Build better apps faster with. Jetpack Compose. Jetpack Compose is Android's modern toolkit for building native UI. It simplifies and accelerates UI development on Android. Quickly bring your app to life with less code, powerful tools, and intuitive Kotlin APIs.
@Preview accepts parameters to customize the way Android Studio will render it. You can add these parameters manually in your code, or click on the gutter icon next to @Preview to display the configuration picker, to let you select and change those configuration parameters. Android Studio offers some features to extend composable previews.
@Preview accepts parameters to customize the way Android Studio will render it. You can add these parameters manually in your code, or click on the gutter icon next to @Preview to display the configuration picker, to let you select and change those configuration parameters.
androidx.compose.ui:ui-*:1.2.0-alpha06 is released. Version 1.2.0-alpha06 contains these commits. Added RequestFocus semantics action to request focus on the focusable target. ( I17b71) Updated parsing of vector drawables to support auto mirroring to flip the content of a VectorPainter if the current layout direction is RTL. ( I79cd9, b/185760237)
ComposeViews placed in view hierarchies that are children of another composition now host child compositions of their ancestors ( I92883) Updated compose's imageFromResource API to reuse the resource drawable cache when loading ImageBitmap objects. ( If3627, b/178751994) androidx.compose.ui:ui-*:1.0.0-alpha11 is released.
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.
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.
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)
)
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With