Home | History | Annotate | Download | only in cronet
      1 gRPC Cronet Transport
      2 ========================
      3 
      4 **EXPERIMENTAL:**  *gRPC's Cronet transport is an experimental API, and is not
      5 yet integrated with our build system. Using Cronet with gRPC requires manually
      6 integrating the gRPC code in this directory into your Android application.*
      7 
      8 This code enables using the [Chromium networking stack
      9 (Cronet)](https://chromium.googlesource.com/chromium/src/+/master/components/cronet)
     10 as the transport layer for gRPC on Android. This lets your Android app make
     11 RPCs using the same networking stack as used in the Chrome browser.
     12 
     13 Some advantages of using Cronet with gRPC:
     14 * Bundles an OpenSSL implementation, enabling TLS connections even on older
     15   versions of Android without additional configuration
     16 * Robust to Android network connectivity changes
     17 * Support for [QUIC](https://www.chromium.org/quic)
     18 
     19 Cronet jars are available on Google's Maven repository. See the example app at
     20 https://github.com/GoogleChrome/cronet-sample/blob/master/README.md. To use
     21 Cronet with gRPC, you will need to copy the gRPC source files contained in this
     22 directory into your application's code, as we do not currently provide a
     23 `grpc-cronet` dependency.
     24 
     25 To use Cronet, you must have the `ACCESS_NETWORK_STATE` permission set in
     26 `AndroidManifest.xml`:
     27 
     28 ```
     29 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     30 ```
     31 
     32 Once the above steps are completed, you can create a gRPC Cronet channel as
     33 follows:
     34 
     35 ```
     36 import io.grpc.cronet.CronetChannelBuilder;
     37 import org.chromium.net.ExperimentalCronetEngine;
     38 
     39 ...
     40 
     41 ExperimentalCronetEngine engine =
     42     new ExperimentalCronetEngine.Builder(context /* Android Context */).build();
     43 ManagedChannel channel = CronetChannelBuilder.forAddress("localhost", 8080, engine).build();
     44 ```
     45 
     46