Context: [#4159 (comment)](https://github.com/grpc/grpc-java/issues/4159#issuecomment-415827641) `Attributes` is appropriate for plumbing optional objects, especially useful for a long plumbing path where components in the middle may not care or see all objects in the container. It's not the case for the `params` on `newNewResolver()`. Both the default port and the proxy detector are guaranteed to be there and the plumbing path is very short. In this case, a first-class object is more appropriate and easier to use. The `Helper` will also have `getSynchronizationContext()` (#2649) and a method to parse and validate service config. We we also considering merging `Listener` into the `Helper`, to make `NameResolver` match the `LoadBalancer` API. |
||
|---|---|---|
| .. | ||
| src | ||
| .gitignore | ||
| README.md | ||
| build.gradle | ||
| proguard-rules.pro | ||
README.md
gRPC Cronet Transport
EXPERIMENTAL: gRPC's Cronet transport is an experimental API, and is not yet integrated with our build system. Using Cronet with gRPC requires manually integrating the gRPC code in this directory into your Android application.
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
Cronet jars are available on Google's Maven repository. See the example app at
https://github.com/GoogleChrome/cronet-sample/blob/master/README.md. To use
Cronet with gRPC, you will need to copy the gRPC source files contained in this
directory into your application's code, as we do not currently provide a
grpc-cronet dependency.
To use Cronet, you must have the ACCESS_NETWORK_STATE permission set in
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();