google-developer-training / basic-android-kotlin-compose-birthday-card-app

Apache License 2.0
125 stars 95 forks source link

Add images: Android Basics with Compose #841

Open chaitanyabhardwaj opened 2 months ago

chaitanyabhardwaj commented 2 months ago

URL of codelab - Codelab

In which task and step of the codelab can this issue be found? Task - 3. Add an Image composable

Step - Preview the Image composable

Describe the problem I followed the exact same directions given in the codelab, but my Android Studio can't render the composable after adding Image composable in it. Although, this is working fine when I'm running it on a physical device.

Steps to reproduce?

  1. Create img composable such as:
    @Composable
    fun GreetingImg(modifier: Modifier = Modifier) {
    val greetingImg = painterResource(id = R.drawable.androidparty)
    val altText: String = "Greeting Img"
    Image(
        painter = greetingImg,
        contentDescription = altText
    )
    }
    Screenshot 2024-09-09 at 6 43 17 AM

Versions Android Studio version: Build #AI-233.14808.21.2331.11709847 API version of the emulator: 34-ext13

Screenshot 2024-09-09 at 6 45 42 AM

Additional information This might be useful:

Screenshot 2024-09-09 at 6 46 52 AM
ovsokolov commented 2 months ago

Same issue

I was getting error in preview androidx.compose.ui.res.ResourceResolutionException: Error attempting to load resource: androidparty

If I convert PNG to WEBP it starts working. Is there a way to show PNG in preview?