Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Okclient in Okclient cannot be applied to (okhttp3.okhttpclient)

I am trying to use Retrofit in one of me projects. I am facing an error with (new OkClient(new OkHttpClient()))

 RestAdapter adapter = new RestAdapter.Builder()
                 .setEndpoint(Constants.GET_API_URL_BASE)
                 .setLogLevel(RestAdapter.LogLevel.FULL)
                 .setClient(new OkClient(new OkHttpClient()))
                 .build();
         apiGet = adapter.create(ApiCalls.class);

The error, underline in red, is on

(new OkHttpClient())

* OkClient(com.squareup.okhttp.OkhttpClient) in OkClient cannot be applied to (okhttp3.OkhttpClient)*

These are my dependences:

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'net.danlew:android.joda:2.7.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp3:okhttp:3.0.1'

Any idea?.
Thanks

like image 914
JoCuTo Avatar asked Jan 23 '16 20:01

JoCuTo


1 Answers

You can use OkHttp3 with Retrofit 1.9 thanks to Jake Wharton and his retrofit1-okhttp3-client

With this library you just need to modify the setClient() in your RestAdapter.Builder to use Ok3Client instead of OkClient.

The code should be like this:

RestAdapter adapter = new RestAdapter.Builder()
             .setEndpoint(Constants.GET_API_URL_BASE)
             .setLogLevel(RestAdapter.LogLevel.FULL)
             .setClient(new Ok3Client(new OkHttpClient()))
             .build();

Here you can find more information about how to use it.

like image 129
Borja Quevedo Avatar answered Nov 15 '22 07:11

Borja Quevedo