question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

okhttp3:logging-interceptor:3.0.0-RC1 wile adding to retrofit2 okhttp3 client

See original GitHub issue

Hi, im using this gradle plugins

    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
    compile 'com.squareup.okhttp3:logging-interceptor:3.0.0-RC1'

This is how I create my service:

        OkHttpClient client = new OkHttpClient();
        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        client.interceptors().add(logging);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();
        APIService service = retrofit.create(APIService.class);

It fails when client.interceptors().add(logging);

With this strack trace:

01-06 09:30:27.944 27005-27005/com.silva.benjamin.ninetyninecoins E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                    Process: com.silva.benjamin.ninetyninecoins, PID: 27005
                                                                                    java.lang.UnsupportedOperationException
                                                                                        at java.util.Collections$UnmodifiableCollection.add(Collections.java:928)
                                                                                        at com.silva.benjamin.ninetyninecoins.util.Helper.service(Helper.java:22)
                                                                                        at com.silva.benjamin.ninetyninecoins.fragments.ConsoleFragment.renderData(ConsoleFragment.java:60)
                                                                                        at com.silva.benjamin.ninetyninecoins.fragments.ConsoleFragment.onCreateView(ConsoleFragment.java:45)
                                                                                        at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
                                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                                        at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
                                                                                        at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                                                                                        at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
                                                                                        at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
                                                                                        at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
                                                                                        at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)
                                                                                        at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
                                                                                        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                                        at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:610)
                                                                                        at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:677)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:940)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                                        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                                                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                                                        at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                                        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
                                                                                        at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
                                                                                        at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5535)
                                                                                        at android.widget.FrameLayout.onMeasure(FrameLayout.java:436)
                                                                                        at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2615)
                                                                                        at android.view.View.measure(View.java:17547)
                                                                                        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2015)
                                                                                        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1173)
                                                                                        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1379)
                                                                                        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
                                                                                        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
                                                                                        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
                                                                                        at android.view.Choreographer.doCallbacks(Choreographer.java:580)
                                                                                        at android.view.Choreographer.doFrame(Choreographer.java:550)
                                                                                        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
                                                                                        at android.os.Handler.handleCallback(Handler.java:739)
                                                                                        at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                        at android.os.Looper.loop(Looper.java:135)
                                                                                        at android.app.ActivityThread.main(ActivityThread.java:5254)
                                                                                        at java.lang.reflect.Method.invoke(
01-06 09:30:30.760 27005-27005/com.silva.benjamin.ninetyninecoins I/Process: Sending signal. PID: 27005 SIG: 9

any lights on what’s going on?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
silva96commented, Jan 6, 2016

Thanks @serj-lotutovici for your quick reply. That solves the problem. But LoggingInterceptor has no builder.

here is the adjusted piece of code

        HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(logging).build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();
        APIService service = retrofit.create(APIService.class);
        return service;
2reactions
serj-lotutovicicommented, Jan 6, 2016

Starting with OkHttp v3 OkHttpClient is immutable and so are the interceptors. To add the logging interceptor (or any other for that mater), use OkHttpClient.Builder.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logging with Retrofit 2 - java - Stack Overflow
This is how to add logging method with the help of ... If you are using Retrofit2 and okhttp3 then you need to...
Read more >
Retrofit - Square Open Source
A type-safe HTTP client for Android and Java. ... Headers that need to be added to every request can be specified using an...
Read more >
Typesafe HTTP Clients with OkHttp and Retrofit - Reflectoring
Introduction to a type-safe HTTP Client OkHttp and Retrofit. ... Once the POST request to add a book to the library is successful, ......
Read more >
How to handle RESTful web Services using Retrofit, OkHttp ...
3rd party // HTTP client - Retrofit with OkHttp implementation ... may have noticed while creating the Retrofit builder instance, we added a ......
Read more >
Using Retrofit 2.x as REST client - Tutorial - Vogella.com
The created OkHttp client has to be added to your Retrofit client with the retrofit2.Retrofit.Builder.client(OkHttpClient) method.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found