Search code examples
androidandroid-jetpack-compose

Jetpack compose can't preview after updating to 1.0.0-rc01


this happened to me only when I updated to 1.0.0-rc01. it says:

The following classes could not be found: - androidx.compose.ui.tooling.preview.ComposeViewAdapter (Fix Build Path, Edit XML, Create Class)

enter image description here

my code:

@Composable
@Preview
fun CenterProgress(){
    Box(
        modifier= Modifier.fillMaxSize(),
        contentAlignment = Alignment.Center
    ){
        CircularProgressIndicator(strokeWidth = 3.dp)
    }
}

Solution

  • Update 07/20/2021: Just download and use the latest AS to fix the problem


    They splitted some packages in rc01 but per @CommonsWare comment (all credits to him) it seems there is a problem with Android Studio version itself. You have 2 options:

    1. Downgrade to beta09 until AS ArcticFox RC1 is out
    2. Try the suggested workaround, use AS Arctic Fox Beta 5 leaving all compose dependencies to 1.0.0-rc01 version and downgrade only ui-tooling to 1.0.0-beta09 (confirmed by comments).

    Extra details

    Here you can find all the classes they moved in 1.0.0-rc01 https://android-review.googlesource.com/c/platform/frameworks/support/+/1739498 and the explanation on why this has been decided.

    In short, you can now do this for some particular optimized scenarios (which should not be the default case):

    debugImplementation "androidx.compose.ui:ui-tooling:1.0.0-rc01"
    implementation "androidx.compose.ui:ui-tooling-preview:1.0.0-rc01"