Skip to content

This package allows OkHttp and Retrofit users to use Cronet as their transport layer, benefiting from features like QUIC/HTTP3 support or connection migration.

License

Notifications You must be signed in to change notification settings

google/cronet-transport-for-okhttp

Cronet Transport for OkHttp and Retrofit

This package allows OkHttp and Retrofit users to use Cronet as their transport layer, benefiting from features like QUIC/HTTP3 support and connection migration.

First steps

Installation

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.

Adding a Cronet dependency

There are several ways to obtain a CronetEngine instance, which is necessary to initialize this library.

From the Play Services

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).