Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@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"
   
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading