Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit gives EOFException only the first time

I'm using framework Retrofit for the first time in my Android project. It handles communication with a backend. Now the strangest part is that on Android 4.4 everything works like a charm. On every version below. I get a RetrofitError type java.io.EOFException. So it fails the first time and then when I push on the retry button it works. So Why is it failing the first time?

I want to fix this because it is annoying that users needs to click retry...

Does someone got a solution for this?

like image 899
user1007522 Avatar asked Mar 12 '14 12:03

user1007522


1 Answers

I found a solution. In Android 4.4 they work with OkHttpclient so thats the reason why it is working on 4.4 and not on the older Android versions.

To solve this add a dependency in gradle:

compile 'com.squareup.okhttp:okhttp-tests:1.5.1'

and create a new client like this:

OkHttpClient client = new OkHttpClient();

add that new client to the restadapter to use this:

setClient(new OkClient(client))

The error should be solved now.

like image 76
user1007522 Avatar answered Nov 18 '22 00:11

user1007522