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: .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?
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?
Share Improve this question edited Jan 19 at 9:32 Stillswarm asked Jan 19 at 9:27 StillswarmStillswarm 797 bronze badges 2- 2 Are you using Coil 2 or Coil 3? Coil 3 requires that you specify a network library to load remote images. – Edric Commented Jan 19 at 9:54
- @Edric thank you for your reply. I was indeed using Coil3 without proper imports. My issue is resolved now! – Stillswarm Commented Jan 19 at 20:00
1 Answer
Reset to default 0As 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).