Stillswarm
Stillswarm

Reputation: 79

Coil Error: Unable to create a fetcher that supports url

I am using Retrofit to fetch data from the Watchmode API. The data of Titles contains a field poster, which contains the url of an image. I am using this function to load this post image:

@Composable
fun AsyncImageLoader(
    imageUrl: String,
    contentDescription: String,
    modifier: Modifier = Modifier
) {
    AsyncImage(
        modifier = modifier,
        model = ImageRequest.Builder(LocalContext.current)
            .data(imageUrl)
            .crossfade(true)
            .build(),
        contentDescription = contentDescription,
        contentScale = ContentScale.Crop,
        placeholder = painterResource(R.drawable.ic_launcher_foreground),
        error = painterResource(R.drawable.baseline_error_outline_24)
    )
}

But I am facing this error when I run the app:

Unable to create a fetcher that supports: https://cdn.watchmode.com/posters/01652190_poster_w185.jpg

This url works perfectly on my browser. Anyhow, I tried with other image urls, but I always face this same error. What am I doing wrong?

Upvotes: 0

Views: 227

Answers (1)

Edric
Edric

Reputation: 26811

As mentioned in the comments, Coil 3 requires that you specify a network library to load remote images.

From the network images documentation:

By default, Coil 3.x does not include support for loading images from the network. This is to avoid forcing a large networking dependency on users who want to use their own networking solution or do not need network URL support (e.g. only loading images from disk).

To add support for fetching images from the network import only one of the following:

implementation("io.coil-kt.coil3:coil-network-okhttp:3.0.4") // Only available on Android/JVM.
implementation("io.coil-kt.coil3:coil-network-ktor2:3.0.4")
implementation("io.coil-kt.coil3:coil-network-ktor3:3.0.4")

If you use OkHttp, that's it. Once imported, network URLs like https://example.com/image.jpg will automatically be supported. If you use Ktor, you need to add supported engines for each platform (see below).

Upvotes: 2

Related Questions