I have been using the preview just fine in the dev-015 release, but when I updated to alpha-01 and alpha-02 it stopped working, I have restarted , cleaned cache, rebuild and the problem just persists
here is my code
val recipeList = listOf(Recipe(R.drawable.header,"Test", listOf("Azucar","Tomate","lasagna")),
Recipe(R.drawable.header,"Test", listOf("Azucar","Tomate","lasagna")),
Recipe(R.drawable.header,"Test", listOf("Azucar","Tomate","lasagna")))
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
RecipeList(recipeList)
}
}
}
@Composable
fun RecipeCard(recipe: Recipe) {
val image = imageResource(R.drawable.header)
Column(modifier = Modifier.padding(16.dp)) {
val imageModifier = Modifier
.preferredHeight(150.dp)
.fillMaxWidth()
.clip(shape = RoundedCornerShape(8.dp))
Image(image,modifier= imageModifier, contentScale = ContentScale.Crop)
Spacer(Modifier.preferredHeight(16.dp))
Text(recipe.title, style = typography.h6)
for(ingredient in recipe.ingredients){
Text(ingredient,style = typography.body2)
}
}
}
@Composable
fun RecipeList(recipeList:List<Recipe>){
LazyColumnFor(recipeList) { item ->
RecipeCard(recipe = item)
}
}
@Preview
@Composable
fun RecipePreview(){
RecipeCard(recipeList[0])
}
data class Recipe(
@DrawableRes val imageResource: Int,
val title: String,
val ingredients: List<String>
)
Here are my dependencies
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.jetexample"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion kotlin_version
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
implementation 'com.google.android.material:material:1.2.0'
//Fundamental building blocks of Compose's programming model and state management, and core runtime for the Compose Compiler Plugin to target.
implementation "androidx.compose.runtime:runtime:$compose_version"
//Fundamental components of compose UI needed to interact with the device, including layout, drawing, and input.
implementation "androidx.compose.ui:ui:$compose_version"
//Build Jetpack Compose UIs with ready to use Material Design Components. This is the higher level entry point of Compose, designed to provide components that match those described at www.material.io.
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
//Write Jetpack Compose applications with ready to use building blocks and extend foundation to build your own design system pieces.
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.foundation:foundation-layout:$compose_version"
//Build animations in their Jetpack Compose applications to enrich the user experience.
implementation "androidx.compose.animation:animation:$compose_version"
//In charge of annotators like @Preview and tooling for render views
implementation "androidx.ui:ui-tooling:$compose_version"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
and my project gradle
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.jetexample"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion kotlin_version
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
implementation 'com.google.android.material:material:1.2.0'
//Fundamental building blocks of Compose's programming model and state management, and core runtime for the Compose Compiler Plugin to target.
implementation "androidx.compose.runtime:runtime:$compose_version"
//Fundamental components of compose UI needed to interact with the device, including layout, drawing, and input.
implementation "androidx.compose.ui:ui:$compose_version"
//Build Jetpack Compose UIs with ready to use Material Design Components. This is the higher level entry point of Compose, designed to provide components that match those described at www.material.io.
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.material:material-icons-extended:$compose_version"
//Write Jetpack Compose applications with ready to use building blocks and extend foundation to build your own design system pieces.
implementation "androidx.compose.foundation:foundation:$compose_version"
implementation "androidx.compose.foundation:foundation-layout:$compose_version"
//Build animations in their Jetpack Compose applications to enrich the user experience.
implementation "androidx.compose.animation:animation:$compose_version"
//In charge of annotators like @Preview and tooling for render views
implementation "androidx.ui:ui-tooling:$compose_version"
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
// Treat all Kotlin warnings as errors
allWarningsAsErrors = true
freeCompilerArgs += '-Xopt-in=kotlin.RequiresOptIn'
// Enable experimental coroutines APIs, including Flow
freeCompilerArgs += '-Xopt-in=kotlin.Experimental'
freeCompilerArgs += '-Xallow-jvm-ir-dependencies'
// Set JVM target to 1.8
jvmTarget = "1.8"
}
}
My emulator just shows this
I have tried everything but it seems is not rendering the preview for me, I have been struggling with jetpack compose each time I update it but cant seem to get it work stable in each update of the API, does someone knows what is happening here ?
Thanks