grpc-java/cronet
Eric Anderson b06942d63b Use Gradle's version catalog
This moves our depedencies into a plain file that can be read and
updated by tooling. While the current tooling is not particularly better
than just using gradle-versions-plugin, it should put us on better
footing. gradle-versions-plugin is actually pretty nice, but will be
incompatible with Gradle 8, so we need to wait a bit to see what the
future holds.

Left libraries as an alias for libs to reduce the commit size and make
it easier to revert if we don't end up liking this approach.

We're using Gradle 7.3.3 where it was an incubating fetaure. But in
Gradle 7.4 is became stable.
2022-06-14 14:04:10 -07:00
..
src all: fix various gradle build warnings 2022-01-18 10:18:16 -08:00
.gitignore cronet: add build.gradle and script for Cronet deps 2018-01-16 09:16:04 -08:00
README.md Update README etc to reference 1.47.0, protobuf plugin 0.8.18 2022-06-02 12:02:16 -07:00
build.gradle Use Gradle's version catalog 2022-06-14 14:04:10 -07:00
proguard-rules.pro cronet: add build.gradle and script for Cronet deps 2018-01-16 09:16:04 -08:00

README.md

gRPC Cronet Transport

EXPERIMENTAL: gRPC's Cronet transport is an experimental API. Its stability depends on upstream Cronet's implementation, which involves some experimental features.

This code enables using the Chromium networking stack (Cronet) as the transport layer for gRPC on Android. This lets your Android app make RPCs using the same networking stack as used in the Chrome browser.

Some advantages of using Cronet with gRPC:

  • Bundles an OpenSSL implementation, enabling TLS connections even on older versions of Android without additional configuration
  • Robust to Android network connectivity changes
  • Support for QUIC

Since gRPC's 1.24 release, the grpc-cronet package provides access to the CronetChannelBuilder class. Cronet jars are available on Google's Maven repository. See the example app at https://github.com/GoogleChrome/cronet-sample/blob/master/README.md.

Example usage:

In your app module's build.gradle file, include a dependency on both grpc-cronet and the Google Play Services Client Library for Cronet

implementation 'io.grpc:grpc-cronet:1.47.0'
implementation 'com.google.android.gms:play-services-cronet:16.0.0'

In cases where Cronet cannot be loaded from Google Play services, there is a less performant implementation of Cronet's API that can be used. Depend on org.chromium.net:cronet-fallback to use this fall-back implementation.

You will also need permission to access the device's network state in your AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Once the above steps are completed, you can create a gRPC Cronet channel as follows:

import io.grpc.cronet.CronetChannelBuilder;
import org.chromium.net.ExperimentalCronetEngine;

...

ExperimentalCronetEngine engine =
    new ExperimentalCronetEngine.Builder(context /* Android Context */).build();
ManagedChannel channel = CronetChannelBuilder.forAddress("localhost", 8080, engine).build();