A Glide network request library based on Cronet.
The network part is provided by okcronet.
- The official Cronet library provided by Glide does not enable HTTP3/QUIC support, which loses its advantages. Source code view CronetEngineSingleton
- And it does not support customization of CronetEngine. The purpose of this library is to provide complete support.
First introduce the Cronet library:
//Import Cronet, this method is recommended in mainland China. You can also use other Cronet versions.
implementation("org.chromium.net:cronet-api:119.6045.31")
implementation("org.chromium.net:cronet-common:119.6045.31")
implementation("org.chromium.net:cronet-embedded:119.6045.31")
// Google Play uses this method
implementation("com.google.android.gms:play-services-cronet:18.0.1")
It is recommended to use this method first, because you can reuse the global CronetEngine of the project.
implementation("io.github.limuyang2:glide-okcronet:1.0.1")
Register in your project AppGlideModule.
@GlideModule
class DemoGlideModule : AppGlideModule() {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
/*
Register the component using your own global CronetEngine.
*/
registry.replace(
GlideUrl::class.java, InputStream::class.java, OkCronetUrlLoader.Factory(App.cronetEngine)
)
}
}
This method will automatically generate a CronetEngine, which will not be reused with the one in the project.
implementation("io.github.limuyang2:glide-okcronet-auto:1.0.0")
No manual registration is required.