Coil3 uses Cronet as the network loading component.
Cronet supports the HTTP1.1, HTTP2, and QUIC/HTTP3 protocols, offering better performance. This library is encapsulated based onokcronet.
implementation("io.github.limuyang2:coil3-cronet:1.0.3")
// coil
implementation("io.coil-kt.coil3:coil:3.0.4")
// coil network functionality
implementation("io.coil-kt.coil3:coil-network-core:3.0.4")
// Add your Cronet dependencies, for example:
implementation("org.chromium.net:cronet-api:141.7340.3")
implementation("org.chromium.net:cronet-common:141.7340.3")
implementation("org.chromium.net:cronet-embedded:141.7340.3")
Add the following code in the onCreate() method of Application:
SingletonImageLoader.setSafe { context ->
ImageLoader.Builder(context)
.crossfade(true)
.components {
add(CronetNetworkFetcherFactory(cronetEngine)) // Add network request component
}
.build()
}Let Application implement the SingletonImageLoader.Factory interface:
class App : Application(), SingletonImageLoader.Factory {
override fun newImageLoader(context: PlatformContext): ImageLoader {
return ImageLoader.Builder(context)
.crossfade(true)
.components {
add(CronetNetworkFetcherFactory(cronetEngine)) // Add network request component
}
.build()
}Please refer to thecoildocumentation