Application Error on HttpLoggingInterceptor

I created a project with Retrofit 2, okhttp and okhttp: logging-interceptor.

private static APIInterface apiInterface; private static RestClient restClient; private static HttpLoggingInterceptor interceptor; OkHttpClient okHttpClient = new OkHttpClient(); okHttpClient.setConnectTimeout(30, TimeUnit.SECONDS); okHttpClient.setReadTimeout(30, TimeUnit.SECONDS); okHttpClient.interceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request original = chain.request(); Request.Builder requestBuilder = original.newBuilder() .header("Accept", "application/json") .header("X-Parse-Application-Id", Constants.PARSE_APP_ID) .header("X-Parse-REST-API-Key", Constants.PARSE_REST_API) .method(original.method(), original.body()); Request request = requestBuilder.build(); return chain.proceed(request); } }); interceptor = new HttpLoggingInterceptor(); // got crash here interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); okHttpClient.interceptors().add(interceptor); 

Here is my footprint:

 java.lang.VerifyError: com/squareup/okhttp/logging/HttpLoggingInterceptor at com.rocker.rest.RestClient.setupRestClient(RestClient.java:62) at com.rocker.rest.RestClient.<clinit>(RestClient.java:39) at com.rocker.fragment.HistoryFragment.onCreateView(HistoryFragment.java:38) 

I do not use okio squared!

+5
source share
1 answer

Did you read this? https://futurestud.io/blog/retrofit-2-log-requests-and-responses

Retrofit 2 makes full use of OkHttp for any network operation. Since OkHttp is a Peer-to-Peer dependency of Retrofit 2, you do not need to add an additional dependency after Retrofit 2 is released as a stable release.

OkHttp 2.6.0 comes with a registration hook as an internal one and you can use it directly for your RetoFit client. Retrofit 2.0.0-beta2 still uses OkHttp 2.5.0. Future releases will bump dependency on higher versions of OkHttp. This is why you need to manually import the registration interceptor. Add the following line to your gradle import in the build.gradle file to extract the interceptor log.

compile 'com.squareup.okhttp: logging-interceptor: 2.6.0'

+4
source

Source: https://habr.com/ru/post/1238393/


All Articles