JoCuTo
JoCuTo

Reputation: 2483

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

Upvotes: 6

Views: 6274

Answers (2)

Borja Quevedo
Borja Quevedo

Reputation: 384

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.

Upvotes: 6

patloew
patloew

Reputation: 1090

For Retrofit versions prior to 2.0.0-beta3 you have to use OkHttp 2. Change your OkHttp dependency to compile 'com.squareup.okhttp:okhttp:2.7.2' or update to Retrofit 2.

Upvotes: 5

Related Questions