This package allows OkHttp and Retrofit users to use Cronet as their transport layer, benefiting from features like QUIC/HTTP3 support and connection migration.
The easiest way to import this library is to include it as a Gradle dependency
in your app's build.gradle
file. Simply add the following line and specify
the desired version. The available VERSION can be found in the
Google Maven Repo
eg 0.1.0
.
implementation 'com.google.net.cronet:cronet-okhttp:VERSION'
You'll also need to specify a dependency on OkHttp (which you likely already have) and add a dependency on core Cronet, which we cover in the next section.
There are several ways to obtain a CronetEngine
instance, which is necessary
to initialize this library.
We recommend using a Google Play Services provider which loads Cronet implementation from the platform. This way the application doesn't need to pay the binary size cost of carrying Cronet and the platform ensures that the latest updates and security fixes are delivered. We also recommend falling back on using plain OkHttp if the platform-wide Cronet isn't available (e.g. because the device doesn't integrate with Google Play Services, or the platform has been tampered with).