87

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)
    }
}
Karim Sinouh
  • 1,312
  • 2
  • 6
  • 20
  • 18
    According to a comment on Kotlinlang Slack's `#compose` channel, previews will not work until you can upgrade to Arctic Fox RC1, which unfortunately is not available yet. That same comment suggested that you could drop the tooling dependencies back to `beta09` and they would work with `rc01` for the main dependencies. Note that I have not tried that yet, so I do not know if it would work. – CommonsWare Jul 02 '21 at 11:59
  • The solution that @CommonsWare mentioned worked for me on Bumblebee Canary 3. – shervinox Jul 19 '21 at 12:35

10 Answers10

78

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"
MatPag
  • 41,742
  • 14
  • 105
  • 114
  • 2
    I tried and I get this Cannot access 'ComposeViewAdapter': it is internal in 'androidx.compose.ui.tooling' – Karim Sinouh Jul 02 '21 at 11:57
  • That's strange... did you update `kotlinCompilerExtensionVersion` in the build.gradle? Maybe could be a problem with AS itself – MatPag Jul 02 '21 at 12:10
  • yes, I did update everything. read the comment above on my question, I think that's the problem – Karim Sinouh Jul 02 '21 at 12:18
  • yes i thinks so, updated the answer accordingly – MatPag Jul 02 '21 at 12:20
  • 7
    Android Studio Artic Fox (2020.3.1) Beta 5 - July 2, 2021. For me it worked the workaround, leave all the compose dependencies to 1.0.0-rc01 version and downgrade only ui-tooling to 1.0.0-beta09. – Yhondri Jul 03 '21 at 23:43
  • 1
    downloaded today the latest AS available, created a fresh project and updated stuff to rc01, to be able to preview I had to use a `debugImplementation` of `ui-tooling:1.0.0-beta07";` instead of the rc01 one. – Gabriel Rohden Jul 06 '21 at 18:37
  • Doesn't look like fixed using rc02 – adek111 Jul 15 '21 at 13:13
  • @adek111 Nope, will not work until AS ArcticFox RC1 is out :/ – MatPag Jul 15 '21 at 13:23
  • I found this answer very helpful. Getting a different error: "androidx.compose.ui.tooling.preview.PreviewActivity is not an Activity subclass or alias" This is with Artic Fox Beta 5 and compose version 1.0.0-rc02 for the other compose dependencies, but still had to downgrade the androidx.compose.ui:ui-tooling version to 1.0.0-beta09 to get the preview to work. – dustin Jul 17 '21 at 19:17
  • 1
    AS RC1 is out, issue seems fixed for me – adek111 Jul 20 '21 at 17:32
  • I got the same issue in `2021.1.1 Patch 3`. The `compose` version is `1.2.0-alpha07`. **Downgraded** `UI-tooling preview` and the `debug implementation` to `1.1.1`. It worked. Using Kotlin version `1.6.20`. – Sagar Patel Apr 17 '22 at 06:07
58

For my case, it's because I left my build variant at "release". Changing it back to "debug" fixes the missing class bug.

enter image description here

the preview functionality is probably from the following line in build.gradle

debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
Angel Koh
  • 12,479
  • 7
  • 64
  • 91
  • 2
    This worked for me too, after I wasted time fiddling around with dependency versions. – Funyinoluwa Kashimawo Oct 25 '22 at 00:49
  • Thank you so much for this comment. It got me a right direction to find out what is wrong in my case – BlizzedRu Jan 24 '23 at 07:48
  • For the custom type try to use `implementation 'androidx.compose.ui:ui-tooling'` – walkmn Jun 22 '23 at 14:26
  • I added the library above suggested by @Angel Koh, but as a regular implementation not debugImplementation to my build.gradle(:app) file, and it worked for me in Android Studio Flamingo | 2022.2.1 `implementation "androidx.compose.ui:ui-tooling:1.4.3"` – jonathan3087 Aug 04 '23 at 21:18
27

Update: This is no longer needed with Android Studio Bumblebee | 2021.1.1 Canary 6 and Android Gradle Plugin 7.1.0-alpha06. Note: Canary 4 already fixed this issue but required a broken version of AGP. This is now also resolved.

In addition to the above answers: here is how to force the ui-tooling version in gradle:

implementation("androidx.compose.ui:ui-tooling:$compose_version") {
    version {
        // TODO: Remove this when Android Studio has become compatible again
        // Android Studio Bumblebee | 2021.1.1 Canary 3 is not compatible with module ui-tooling 1.0.0-rc01 or higher.
        // The Run Configuration for Composable Previews that Android Studio makes expects a PreviewActivity class
        // in the `androidx.compose.ui.tooling.preview` package, but it was moved in 1.0.0-rc01, and thus causes error:
        // "androidx.compose.ui.tooling.preview.PreviewActivity is not an Activity subclass or alias".
        // For more, see: https://stackoverflow.com/questions/68224361/jetpack-compose-cant-preview-after-updating-to-1-0-0-rc01
        strictly("1.0.0-beta09")
    }
}

Rob Meeuwisse
  • 2,847
  • 1
  • 17
  • 21
19

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"

I am talking as of Feb-2023

Chirag Thummar
  • 665
  • 6
  • 16
3

I tried it like the comment above me and it actually helped me only that i had to delete the implementation of :

Link to Artic Fox Beta 5:
https://developer.android.com/studio/preview

androidx.compose.ui:ui-tooling-preview.
My compose config looks like the following:

android {

def compose_version = '1.0.0-rc01'


composeOptions {
  kotlinCompilerExtensionVersion "$compose_version"
}

dependencies {
  def compose_version = '1.0.0-rc01'
/**Compose Related*/

    implementation "androidx.compose.compiler:compiler:$compose_version"
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.activity:activity-compose:1.3.0-rc01"
    implementation "androidx.compose.material:material:$compose_version"

    implementation "androidx.compose.ui:ui-tooling:1.0.0-beta09"
//    Need to comment this two lines to work on artic fox
//    implementation "androidx.compose.ui:ui-tooling:$compose_version"
//    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    /**Accompanist*/
    // Coil
    implementation 'dev.chrisbanes.accompanist:accompanist-insets:0.6.2'
    implementation "com.google.accompanist:accompanist-coil:0.13.0"
    implementation "androidx.compose.runtime:runtime:$compose_version"
    implementation "androidx.compose.runtime:runtime-livedata:$compose_version"

    /** Material Icons */
    implementation "androidx.compose.material:material-icons-extended:$compose_version"


    // Jetpack Compose Integration
    implementation "androidx.navigation:navigation-compose:2.4.0-alpha04"
}

}
Augusto Alonso
  • 334
  • 3
  • 5
3

To people still get the error when downgrade the ui-tooling library:

Make sure you don't have library that have dependency on ui-tooling:1.0.0-rc01 You can find that out by using ./gradlew app:dependencies in your android studio terminal

In my case, I'm using com.google.accompanist:accompanist-swiperefresh:13.0.0 which depend on ui-tooling:1.0.0-rc01. Preview is working when I downgrade to accompanist-swiperefresh:12.0.0

Kelvin Yip
  • 31
  • 2
  • 1
    The accompanist versions mentioned are incorrect, they should be `0.13.0` and `0.12.0`. Besides that, great find! Solved my issues. – steurt Jul 08 '21 at 07:19
1

Been messing around with this. I have a project that has several modules and several build variants. For me, the key was to set each variant (except release) to be debuggable in its modules' build.gradle file:

buildTypes {
    debug {
        minifyEnabled false
        debuggable true // THIS
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
...
}

After that, no matter what build variant I had selected the preview would show.

This is on Android Studio Electric Eel | 2022.1.1 Patch 1

project build.gradle

plugins {
    id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
    ...
}

app build.gradle

android {
    ...
    composeOptions {
        kotlinCompilerExtensionVersion '1.4.3'
    }
    ...
}

dependencies {
    ...
    implementation "androidx.compose.ui:ui-tooling-preview:1.3.3"
    debugImplementation "androidx.compose.ui:ui-tooling:1.3.3"
    ...
}
0

Adding the following dependency fixed my issue with the preview in a library module:

debugImplementation 'androidx.customview:customview-poolingcontainer:1.0.0'
aminography
  • 21,986
  • 13
  • 70
  • 74
0

If you are using custom build type (instead debug), you can use implementation instead of debugImplementation:

implementation 'androidx.compose.ui:ui-tooling'
walkmn
  • 2,322
  • 22
  • 29
-1

On my case, where I have a "design system" module providing all compose-related dependencies, I had to add the following dependency:

implementation("androidx.activity:activity-compose:1.4.0")
rsicarelli
  • 1,013
  • 1
  • 11
  • 28