google / cronet-transport-for-okhttp

This package allows OkHttp and Retrofit users to use Cronet as their transport layer, benefiting from features like QUIC/HTTP3 support or connection migration.
Apache License 2.0
452 stars 34 forks source link

How to use it in Android? #1

Closed forgetW closed 2 years ago

forgetW commented 2 years ago

How to use it in Android? What are the versions of okhttp and other dependencies?

ag2s20150909 commented 2 years ago

First copy Java Files to your project

//Cronet embedded version
implementation 'org.chromium.net:cronet-embedded:101.4951.41'
//or use play services version
implementation 'com.google.android.gms:play-services-cronet:18.0.1'

// guava
implementation 'com.google.guava:guava:31.1-android'

// annotation
implementation 'androidx.annotation:annotation:1.3.0'

//okhttp 3.x or 4.x or 5.x
implementation 'com.squareup.okhttp3:okhttp:4.9.3'

Create CronetEngine

CronetEngine engine = new CronetEngine.Builder(applicationContext).build();

Create OkhttpClient

OkHttpClient okhttpclient=new OkHttpClient.Builder()
   .....
   .addInterceptor(CronetInterceptor.newBuilder(engine).build()) //must be latest application Interceptor
   .build();
FireMasterK commented 2 years ago

I have implementation 'org.chromium.net:cronet-embedded:101.4951.41' in my application, but I don't have the CronetInterceptor class, only the cronet specific classes.

Danstahrg commented 2 years ago

Hi,

We don't publish pre-compiled binaries yet (coming soon, stay tuned).

For now, you either need to copy the code over to your application project; or build the library separately and add it as a compiled dependency.

The library works with OkHttp 3+ and doesn't include OkHttp classes (and their dependencies) in the jar. Instead, it depends on your application's classpath so you can keep using the OkHttp version you like.

FireMasterK commented 2 years ago

Any progress for a precompiled maven dependency? I want to avoid adding a gitmodule / copying this directly to my application code.

snowinszu commented 2 years ago

We are also waiting for the pre-compiled binaries to be published, thanks in advance.

Danstahr commented 2 years ago

Apologies for the wait everyone, I'm on parental leave. Expect an update the week after next.

Danstahrg commented 2 years ago

Sorry for the delay everyone, I ended up taking a couple more weeks. I'll aim to at least add a binary release on GitHub this week.

FireMasterK commented 2 years ago

Would that be usable by maven/gradle directly? That's what I'm looking for currently in my use case.

Danstahrg commented 2 years ago

I created a preliminary release on https://github.com/google/cronet-transport-for-okhttp/releases/tag/release-ed5851e and added instructions on how to use it. I'll aim to add a proper Maven artifact ASAP.

Danstahrg commented 2 years ago

This artifact, including dependencies, is now also available as com.google.net.cronet:cronet-okhttp:0.1.0 natively from Maven.

raymondctc commented 1 year ago

Any plan to publish another update to maven? as we need commit 0a43782448 fix, thank you! 🙏

Danstahrg commented 1 year ago

Happy New Year everyone, it'll be a bit of a busy week for me but I'll see what we can do to have another one-off Maven release.