Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

coil 2.6.0 does not resolve in KMP project

I have a problem in my KMP project. I would like to use coil to render images but I am currently unable to resolve the lib. I added it in the following places:

libs.versions.toml:

[versions]
coil = "2.6.0"

[libraries]
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }

build.gradle.kts (:shared):

androidMain.dependencies {
    implementation(libs.coil.compose)
}

Now the project is synced successfully but as soon as i try to use AsyncImage it wont resolve.

this is in my mainActivity:

AsyncImage(
    model = "https://fastly.picsum.photos/id/521/200/300.jpg?hmac=_MGlUtHw5IBlsNL7YvJ9lTMo4Ge605GWQwuKGxWIWU",
    contentDescription = null,
)

I can't import AsyncImage, does anyone have an idea what I'm missing?

I tried different versions, cleaning project, resetting caches and restarting

I expect being able to import AsyncImage

like image 606
Bukinski Avatar asked Dec 06 '25 16:12

Bukinski


2 Answers

coil 2.6.0 does not support kmp but there is a beta version that does and it worked fine in my project. reference : https://coil-kt.github.io/coil/upgrading_to_coil3/ so in short change coil version with this one coil = "3.0.0-alpha06" and it should work fine since there is no obvious problem in your implementation.

it also work with compose multiplatform so you can just implement in in the common main instead of android only :

with(libs.coil){
            implementation(compose)
            implementation(network)
        }
like image 86
Mohamed Mabrouki Avatar answered Dec 09 '25 04:12

Mohamed Mabrouki


libs.versions.toml:

[versions]
coil = "3.0.0-rc01"
coilNetworkKtor3 = "3.0.0-rc01"
ktor = "3.0.0"
        
[libraries]
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coil-network-ktor3 = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coilNetworkKtor3" }
coil-svg = { module = "io.coil-kt.coil3:coil-svg", version.ref = "coil" }
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }

build.gradle.kts (:shared):

commonMain.dependencies {
    implementation(libs.coil.compose)
    implementation(libs.coil.svg)
    implementation(libs.coil.network.ktor3)
    implementation(libs.ktor.client.core)
}
androidMain.dependencies {
    implementation(libs.ktor.client.okhttp)
}
iosMain.dependencies {
    implementation(libs.ktor.client.darwin)
}
        

Example:

AsyncImage(
    model = "https://i.pinimg.com/736x/ae/2e/70/ae2e70f6660753cf4353ff443d3b1726.jpg",
    contentDescription = "im"
)

And add it to your AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"/>

        
        
        
        
        
like image 28
hrsh Avatar answered Dec 09 '25 05:12

hrsh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!