NoSuchMethodError if i am using okhttp 2.0 and the latest retrofit?
android, gradle, okhttp, retrofit
Solution
The answer by Jake Wharton in google+ we can do like this. I throw away the OkClient in retrofit.
public class RetrofitHttpClient extends UrlConnectionClient {
private static final int CONNECT_TIMEOUT_MILLIS = 60 * 1000; // 30s
private static final int READ_TIMEOUT_MILLIS = 85 * 1000; // 45s
private static OkUrlFactory generateDefaultOkUrlFactory() {
OkHttpClient client = new com.squareup.okhttp.OkHttpClient();
client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
return new OkUrlFactory(client);
}
private final OkUrlFactory factory;
public RetrofitHttpClient() {
factory = generateDefaultOkUrlFactory();
}
@Override protected HttpURLConnection openConnection(Request request) throws IOException {
return factory.open(new URL(request.getUrl()));
}
}
I have tested this code. it's work fine.
Problem
Could not find method com.squareup.okhttp.OkHttpClient.open, referenced from method retrofit.client.OkClient.openConnection. below is my gradle config ``` compile 'com.squareup.okhttp:okhttp:+' compile 'com.squareup.okhttp:okhttp-urlconnection:+' compile 'com.squareup.retrofit:retrofit:+' ```