androidandroid-jetpack-composecoil

Jetpack Compose Coil not found


I'm already replacing XML code with Jetpack Compose and I need to load image to Image component in Jetpack Compose. I've used Glide in legacy code so I imported Coil library but its not working in my code. I already cleared cache and rebuilt project but its still not recognizing Coil components.

Gradle:

implementation("io.coil-kt:coil:2.3.0")

Code:

@Composable
fun userAvatar(url: String){
    Box(
        modifier = Modifier
            .size(50.dp)
            .padding(4.dp)
    ) {
        AsyncImage(
            model = url,
            contentDescription = "User Avatar",
            modifier = Modifier
                .fillMaxSize()
                .clip(CircleShape)
        )
    }
}

Getting

"Unresolved reference: AsyncImage"

.

I found I can use also something like this:

val painter: Painter = rememberCoilPainter(request = url, fadeIn = true)

and then apply it to regular Image but this function also says "Unresolved reference".


Solution

  • You are importing the wrong coil lib version for the compose.

    implementation("io.coil-kt:coil:2.3.0"
    

    you need to import the coil lib made for Jetpack Compose. Replace it with this

    implementation "io.coil-kt:coil-compose:2.4.0"