Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crash on HttpLoggingInterceptor

I've created 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 trace:

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'm not using okio by squareup!

like image 658
Drake Avatar asked Dec 16 '15 15:12

Drake


1 Answers

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

Retrofit 2 completely relies on OkHttp for any network operation. Since OkHttp is a peer dependency of Retrofit 2, you won’t need to add an additional dependency once Retrofit 2 is released as a stable release.

OkHttp 2.6.0 ships with a logging interceptor as an internal dependency and you can directly use it for your Retrofit client. Retrofit 2.0.0-beta2 still uses OkHttp 2.5.0. Future releases will bump the dependency to higher OkHttp versions. That’s why you need to manually import the logging interceptor. Add the following line to your gradle imports within your build.gradle file to fetch the logging interceptor dependency.

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

like image 140
rafakob Avatar answered Oct 07 '22 00:10

rafakob