Annyce Davis

Davis Technology Consulting

  • Home
  • About Me
  • Blog
  • Courses
  • Newsletter

The Little Things: Didn’t read the manual

October 1, 2024 by Annyce Davis

This series is dedicated to the little things in programming that make you want to bang your head against the wall. Today’s post is about: when you didn’t read the manual.

Attempting to load an image

Loading an image with Jetpack Compose is straightforward. Since I use the Coil image loading library when developing apps with Android Views, I decided to do the same with Compose. The instructions couldn’t be simpler.

Import the extension library.

implementation("io.coil-kt:coil-compose:2.7.0")

Then use the AsyncImage composable to load and display an image.

AsyncImage(
    model = "https://example.com/image.jpg",
    contentDescription = null,
)

I dutifully added the extension and dropped the new composable into my layout.

Column(
   modifier = Modifier
      .fillMaxSize()
      .padding(innerPadding),
   verticalArrangement = Arrangement.Center,
   horizontalAlignment = Alignment.CenterHorizontally
) {
    AsyncImage(
        model = "https://bit.ly/android_dev_image1",
        modifier = Modifier.size(300.dp),
        contentScale = ContentScale.Fit,
        contentDescription = "friendly robot"
    )
}

Instead of a cute friendly robot, I had a blank screen. 🙃 Thus began my descent into madness.

No image loaded

Getting to the root of the problem

In these situations I tend to remove variables one-by-one. I dropped the modifier and then the contentScale on the image composable. Still no image.

Next, I thought maybe the bit.ly redirection was causing the problem. So I dropped in the exact URL, “https://api.dicebear.com/8.x/bottts/svg?seed=Bubba“. No dice.

Maybe my image was corrupt? Tried random online tools. The image was fine. What gives?! 🧐 Next, I tried a different image, “https://2873199.youcanlearnit.net/images/chili_bottle.webp“. And it loaded! But I didn’t want a giant bottle of olive oil, I wanted my cute robot.

So I stared into the darkness of my Dracula-themed IDE. There was something fundamentally missing. The AsyncImage composable could load WebP images, but not SVG? 👀 I was ready to message the maintainer. But…

Before I took such a bold stand, I decided to read the documentation again. Specifically I just searched SVG. And wouldn’t you know, SVGs require a little special treatment. 🤦🏽‍♀️

Screenshot from the Coil documentation

I dusted off the keyboard. Then I added the SVG extension library and the ImageLoaderFactory implementation.

Image loaded

And yeah, it worked! My SVG image was loaded properly. I had my cute little robot and was on with my day. 🤖

Just one of those little things. fin

Share this:

  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to share on WhatsApp (Opens in new window) WhatsApp
  • Click to share on Reddit (Opens in new window) Reddit

Related

Filed Under: Android, Software Development Tagged With: Android, Jetpack Compose, The Little Things

Follow Me

  • Bluesky

Categories

  • Android (60)
  • Career (5)
  • Communication (4)
  • Flutter (1)
  • Git (4)
  • Gradle (4)
  • Grails (23)
  • iOS (1)
  • Java (8)
  • JavaScript (6)
  • Kotlin (17)
  • Life (5)
  • Public Speaking (26)
  • Revenue (2)
  • RxJava (1)
  • Software Development (13)
  • Twitter (3)
  • Uncategorized (11)
  • Video Course (5)

Follow Me

  • Bluesky

Copyright © 2025 · All Rights Reserved · Log in

 

Loading Comments...