Okhttp: java.lang.NoSuchMethodError: No virtual method names()Ljava/util/Set; in class Lokhttp3/Headers

Created on 6 Apr 2018  路  5Comments  路  Source: square/okhttp

Hi guys,

I'm using retrofit (2.4.0) and OkHttp Interceptor (3.10.0) in an Android project and I'm facing a crash on a request.

I'm using Proguard to optimize and shrink the code.

java.lang.NoSuchMethodError: No virtual method names()Ljava/util/Set; in class Lokhttp3/Headers; or its super classes (declaration of 'okhttp3.Headers' appears in /data/app/package==/base.apk)
        at com.android.tools.profiler.agent.okhttp.OkHttp3Interceptor.toMultimap(OkHttp3Interceptor.java:102)
        at com.android.tools.profiler.agent.okhttp.OkHttp3Interceptor.trackRequest(OkHttp3Interceptor.java:71)
        at com.android.tools.profiler.agent.okhttp.OkHttp3Interceptor.intercept(OkHttp3Interceptor.java:45)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
        at okhttp3.RealCall.execute(RealCall.java:77)
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:180)
        at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:42)
        at io.reactivex.Observable.subscribe(Observable.java:11194)
        at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34)
        at io.reactivex.Observable.subscribe(Observable.java:11194)
        at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
        at io.reactivex.Single.subscribe(Single.java:3096)
        at io.reactivex.internal.operators.single.SingleFlatMap$SingleFlatMapCallback.onSuccess(SingleFlatMap.java:84)
        at io.reactivex.internal.operators.single.SingleCreate$Emitter.onSuccess(SingleCreate.java:68)
        at package.AphaelService$Factory$create$1.subscribe(MyRetrofitService.kt:226)

I was able to get rid of this issue adding this Proguard line to my configuration :
-keep class okhttp3.Headers { *; }

I checked the versions of both retrofit and OkHttp and they are matching each other (compatible).

Thanks

Most helpful comment

This isn't a bug in OkHttp. ProGuard is removing that method and then the Android Studio network profiler code that is injected into your APK is assuming the method will be present. You should file a bug at https://issuetracker.google.com/issues/new?component=317727 that the network profiler needs to either bundle ProGuard rules for the methods they require or put their API onto the ProGuard classpath so anything it uses is automatically retained.

All 5 comments

This isn't a bug in OkHttp. ProGuard is removing that method and then the Android Studio network profiler code that is injected into your APK is assuming the method will be present. You should file a bug at https://issuetracker.google.com/issues/new?component=317727 that the network profiler needs to either bundle ProGuard rules for the methods they require or put their API onto the ProGuard classpath so anything it uses is automatically retained.

You can also disable the network profiler in AS if you want.

Also your workaround is fine, as it will keep all methods in the class (not just the one the profiler needs) so that they are available to the injected code.

Sorry for creating an issue for a bug in AS, I should have checked that before...

Thanks for your reply, happy coding !

I was able to get rid of this issue adding this Proguard line to my configuration :
-keep class okhttp3.Headers { *; }

This just worked for me too.

Weird that this problem manifested for me for the first time on June 7th 2018, since we do weekly builds, maybe after a gradle upgrade...

The right answer would be "deactivate Android Studio profiling" since it's the advanced profiler that injects these classes at runtime.

Go to "Edit configuration" on your gradle task that launch the app, then from the "Profiling" tab uncheck the "Enable advanced profiling" entry.

Of course this is an Android Studio bug that you can track here

Was this page helpful?
0 / 5 - 0 ratings