Reputation: 1672
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)
my code:
@Composable
@Preview
fun CenterProgress(){
Box(
modifier= Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
){
CircularProgressIndicator(strokeWidth = 3.dp)
}
}
Upvotes: 106
Views: 30767
Reputation: 93
This happened to me in release variant, try switching back to debug variant.
Upvotes: 4
Reputation: 61
Was Facing the same issue on Android Studio Giraffe using compose BOM version (2023.10.01). The Preview was working on the start but stopped after the application got compiled on the emulator. The issue was solved by implementing both:
debugImplementation "androidx.compose.ui:ui-tooling"
implementation "androidx.compose.ui:ui-tooling-preview"
Good to go!
Upvotes: 4
Reputation: 813
This is the configuration that worked for me, I am using composable in Fragment and the preview was not showing.
implementation(platform('androidx.compose:compose-bom:2023.10.00'))
implementation("androidx.compose.ui:ui-tooling")
implementation("androidx.compose.material3:material3")
Upvotes: 0
Reputation: 77
This solution worked for me like a boss.
I just replaced below dependency
debugImplementation "androidx.compose.ui:ui-tooling-preview:$latest_version"
with this one
debugImplementation "androidx.compose.ui:ui-tooling:$latest_version"
Actually 'preview' word in dependency causes problem.
Upvotes: 3
Reputation: 2391
If you are using custom build type (instead debug
), you can use implementation
instead of debugImplementation
:
implementation 'androidx.compose.ui:ui-tooling'
Upvotes: 4
Reputation: 688
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"
...
}
Upvotes: 2
Reputation: 3172
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
Upvotes: 35
Reputation: 22832
Adding the following dependency fixed my issue with the preview in a library module:
debugImplementation 'androidx.customview:customview-poolingcontainer:1.0.0'
Upvotes: 1
Reputation: 1023
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")
Upvotes: -1
Reputation: 44803
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.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"
Upvotes: 84
Reputation: 13485
For my case, it's because I left my build variant at "release". Changing it back to "debug" fixes the missing class bug.
the preview functionality is probably from the following line in build.gradle
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
Upvotes: 109
Reputation: 2937
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")
}
}
Upvotes: 27
Reputation: 31
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
Upvotes: 3
Reputation: 344
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"
}
}
Upvotes: 3