Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)     } } 
like image 293
Karim Sinouh Avatar asked Jul 02 '21 11:07

Karim Sinouh


People also ask

What is the latest version of jetpack compose?

Today, we're releasing version 1.2 of Jetpack Compose, Android's modern, native UI toolkit, continuing to build out our roadmap.

How do I get the screen size on jetpack compose?

If you want to get the size in pixels: val screenDensity = configuration. densityDpi / 160f and multiply with dp, for example val screenHeight = configuration. screenHeightDp.

What is LazyColumn in jetpack compose?

A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.

Does jetpack compose increase app size?

When you start adopting Compose in your app, you can see an increase in APK size and build time which will decrease and surpass the original metric once the project is fully migrated to Compose. Note: During Tivi's migration to Compose, there were lots of dependency updates such as Gradle (from 6.0.


2 Answers

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" 
like image 132
MatPag Avatar answered Sep 20 '22 01:09

MatPag


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")     } }  
like image 29
Rob Meeuwisse Avatar answered Sep 23 '22 01:09

Rob Meeuwisse