unable to load android socket classes java.lang.NoSuchMethodException: com.android.org.conscrypt.OpenSSLSocketImpl.setUseSessionTickets [boolean]

Viewed 2726

Hi everyone I am facing a problem with my retrofit code on an api call, I am posting the stack trace below please have a look at it:

    Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setUseSessionTickets(Z)V (greylist-max-q,core-platform-api, reflection, denied)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp: unable to load android socket classes
2021-09-25 19:02:08.588 30949-30949/W/OkHttp: java.lang.NoSuchMethodException: com.android.org.conscrypt.OpenSSLSocketImpl.setUseSessionTickets [boolean]
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at java.lang.Class.getMethod(Class.java:2072)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at java.lang.Class.getDeclaredMethod(Class.java:2050)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.android.AndroidSocketAdapter.<init>(AndroidSocketAdapter.kt:34)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.android.StandardAndroidSocketAdapter.<init>(StandardAndroidSocketAdapter.kt:31)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.android.StandardAndroidSocketAdapter$Companion.buildIfSupported(StandardAndroidSocketAdapter.kt:57)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.android.StandardAndroidSocketAdapter$Companion.buildIfSupported$default(StandardAndroidSocketAdapter.kt:50)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.AndroidPlatform.<init>(AndroidPlatform.kt:44)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported(AndroidPlatform.kt:239)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.Platform$Companion.findPlatform(Platform.kt:211)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.Platform$Companion.access$findPlatform(Platform.kt:179)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.internal.platform.Platform.<clinit>(Platform.kt:180)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:219)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at okhttp3.OkHttpClient$Builder.build(OkHttpClient.kt:955)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at .ui.retroPack.RetrofitClient.getClient(RetrofitClient.java:35)
2021-09-25 19:02:08.588 30949-30949/W/OkHttp:     at .ui.retroPack.RetrofitClient.getAPIService(RetrofitClient.java:52)
2021-09-25 19:02:08.588 30949-30949/

This java.lang.NoSuchMethodException: only occurs when the connection is being established for the first time with the server, although api is still getting success response and everything works fine in debug build and when I hit the api again it does not shows the same exception message in the android studio logcat.

I am facing problem with the app in production, I get the same exception message in production as well and api is being called and i can see the response as well but in production screen in not moving to next screen as it should. Is this issue because of java.lang.NoSuchMethodException this exception or there is some other problem with my app in production. If anybody have any possible solution or suggestion please share. It will be of great help for me, Thanks.

1 Answers

I hit a similar error on API 30 and com.squareup.okhttp3:okhttp:4.2.2.

The problem was that OkHttp uses refection to access some parts of the core Android SDK. So OkHttp is strongly coupled to API version.

In my case upgrading to com.squareup.okhttp3:okhttp:4.9.3 fixed the issue but the required version will depend on your target SDK.

More info here: https://github.com/amplitude/Amplitude-Android/issues/309

Related