Okhttp: OkHttp 4.3.1 spams log, didn't find class "org.conscrypt.ConscryptHostnameVerifier" on path

Created on 30 Jan 2020  Â·  21Comments  Â·  Source: square/okhttp

A trivial use of OkHttp 4.3.1 causes some spam in the device log.

https://gist.github.com/jamesonwilliams/8ab7237083467ed3cb8680115a3e3829

This code:

disposable = Single.fromCallable(() ->
    new OkHttpClient().newCall(new Request.Builder()
        .url("https://raw.githubusercontent.com/square/okhttp/master/README.md")
        .get()
        .build())
    .execute()
    .body()
    .string()
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
    textView::setText,
    failure -> textView.setText(Log.getStackTraceString(failure))
);

With this OkHttp:

implementation 'com.squareup.okhttp3:okhttp:4.3.1'

Causes this spam, as the out-of-the-box default:

I: Rejecting re-init on previously-failed class java.lang.Class<okhttp3.internal.platform.ConscryptPlatform$configureTrustManager$1>: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/conscrypt/ConscryptHostnameVerifier;
I:     at okhttp3.internal.platform.android.SocketAdapter okhttp3.internal.platform.android.ConscryptSocketAdapter$Companion.buildIfSupported() (ConscryptSocketAdapter.kt:62)
I:     at void okhttp3.internal.platform.AndroidPlatform.<init>() (AndroidPlatform.kt:44)
I:     at okhttp3.internal.platform.Platform okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported() (AndroidPlatform.kt:212)
I:     at okhttp3.internal.platform.Platform okhttp3.internal.platform.Platform$Companion.findPlatform() (Platform.kt:207)
I:     at okhttp3.internal.platform.Platform okhttp3.internal.platform.Platform$Companion.access$findPlatform(okhttp3.internal.platform.Platform$Companion) (Platform.kt:169)
I:     at void okhttp3.internal.platform.Platform.<clinit>() (Platform.kt:170)
I:     at void okhttp3.OkHttpClient.<init>(okhttp3.OkHttpClient$Builder) (OkHttpClient.kt:220)
I:     at void okhttp3.OkHttpClient.<init>() (OkHttpClient.kt:212)
I:     at java.lang.String okhttp.conscrypt.issue.MainActivity.lambda$onCreate$0() (MainActivity.java:28)
I:     at java.lang.Object okhttp.conscrypt.issue.-$$Lambda$MainActivity$HFmP7xhC1oUdC6d5U0mKIdLTGns.call() (lambda:-1)
I:     at void io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(io.reactivex.SingleObserver) (SingleFromCallable.java:44)
I:     at void io.reactivex.Single.subscribe(io.reactivex.SingleObserver) (Single.java:3666)
I:     at void io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run() (SingleSubscribeOn.java:89)
I:     at void io.reactivex.Scheduler$DisposeTask.run() (Scheduler.java:578)
I:     at void io.reactivex.internal.schedulers.ScheduledRunnable.run() (ScheduledRunnable.java:66)
I:     at java.lang.Object io.reactivex.internal.schedulers.ScheduledRunnable.call() (ScheduledRunnable.java:57)
I:     at void java.util.concurrent.FutureTask.run() (FutureTask.java:237)
I:     at void java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run() (ScheduledThreadPoolExecutor.java:272)
I:     at void java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) (ThreadPoolExecutor.java:1133)
I:     at void java.util.concurrent.ThreadPoolExecutor$Worker.run() (ThreadPoolExecutor.java:607)
I:     at void java.lang.Thread.run() (Thread.java:761)
I: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.conscrypt.ConscryptHostnameVerifier" on path: DexPathList[[zip file "/data/app/okhttp.conscrypt.issue-2/base.apk"],nativeLibraryDirectories=[/data/app/okhttp.conscrypt.issue-2/lib/x86, /system/lib, /vendor/lib]]
I:     at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
I:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
I:     at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
I:     at okhttp3.internal.platform.android.SocketAdapter okhttp3.internal.platform.android.ConscryptSocketAdapter$Companion.buildIfSupported() (ConscryptSocketAdapter.kt:62)
I:     at void okhttp3.internal.platform.AndroidPlatform.<init>() (AndroidPlatform.kt:44)
I:     at okhttp3.internal.platform.Platform okhttp3.internal.platform.AndroidPlatform$Companion.buildIfSupported() (AndroidPlatform.kt:212)
I:     at okhttp3.internal.platform.Platform okhttp3.internal.platform.Platform$Companion.findPlatform() (Platform.kt:207)
I:     at okhttp3.internal.platform.Platform okhttp3.internal.platform.Platform$Companion.access$findPlatform(okhttp3.internal.platform.Platform$Companion) (Platform.kt:169)
I:     at void okhttp3.internal.platform.Platform.<clinit>() (Platform.kt:170)
I:     at void okhttp3.OkHttpClient.<init>(okhttp3.OkHttpClient$Builder) (OkHttpClient.kt:220)
I:     at void okhttp3.OkHttpClient.<init>() (OkHttpClient.kt:212)
I:     at java.lang.String okhttp.conscrypt.issue.MainActivity.lambda$onCreate$0() (MainActivity.java:28)
I:     at java.lang.Object okhttp.conscrypt.issue.-$$Lambda$MainActivity$HFmP7xhC1oUdC6d5U0mKIdLTGns.call() (lambda:-1)
I:     at void io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(io.reactivex.SingleObserver) (SingleFromCallable.java:44)
I:     at void io.reactivex.Single.subscribe(io.reactivex.SingleObserver) (Single.java:3666)
I:     at void io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run() (SingleSubscribeOn.java:89)
I:     at void io.reactivex.Scheduler$DisposeTask.run() (Scheduler.java:578)
I:     at void io.reactivex.internal.schedulers.ScheduledRunnable.run() (ScheduledRunnable.java:66)
I:     at java.lang.Object io.reactivex.internal.schedulers.ScheduledRunnable.call() (ScheduledRunnable.java:57)
I:     at void java.util.concurrent.FutureTask.run() (FutureTask.java:237)
I:     at void java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run() (ScheduledThreadPoolExecutor.java:272)
I:     at void java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) (ThreadPoolExecutor.java:1133)
I:     at void java.util.concurrent.ThreadPoolExecutor$Worker.run() (ThreadPoolExecutor.java:607)
I:     at void java.lang.Thread.run() (Thread.java:761)

I am ___not___ using Conscrypt. I do _not_ include it in my Android project's Gradle dependencies. I _do_ agree with the view point of this StackOverflow comment from kroegerama@:

If okHttp needs conscrypt, it should reference this library instead of forcing us to add this dependency. This should not be marked as accepted. Better file a bug report on square's github repo. – kroegerama Nov 7 '19 at 14:07

bug

Most helpful comment

Hi! I just noticed that the error keeps occurring with OkHttp 4.8.1, along with other missing classes from bouncycastle, openjsse and android:

okhttp3.internal.platform.ConscryptPlatform$platformTrustManager$2: can't find superclass or interface org.conscrypt.ConscryptHostnameVerifier
okhttp3.internal.io.FileSystem$Companion$SYSTEM$1: can't find referenced class okhttp3.internal.io.FileSystem$DefaultImpls
okhttp3.internal.platform.BouncyCastlePlatform: can't find referenced class org.bouncycastle.jsse.BCSSLSocket
okhttp3.internal.platform.BouncyCastlePlatform: can't find referenced class org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
okhttp3.internal.platform.BouncyCastlePlatform: can't find referenced class org.bouncycastle.jsse.BCSSLParameters
okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.ConscryptHostnameVerifier
okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
okhttp3.internal.platform.ConscryptPlatform$Companion: can't find referenced class org.conscrypt.Conscrypt
okhttp3.internal.platform.ConscryptPlatform$platformTrustManager$2: can't find referenced class org.conscrypt.ConscryptHostnameVerifier
okhttp3.internal.platform.Jdk9Platform: can't find referenced method 'void setApplicationProtocols(java.lang.String[])' in library class javax.net.ssl.SSLParameters
okhttp3.internal.platform.Jdk9Platform: can't find referenced method 'java.lang.String getApplicationProtocol()' in library class javax.net.ssl.SSLSocket
okhttp3.internal.platform.OpenJSSEPlatform: can't find referenced class org.openjsse.javax.net.ssl.SSLParameters
okhttp3.internal.platform.OpenJSSEPlatform: can't find referenced class org.openjsse.javax.net.ssl.SSLSocket
okhttp3.internal.platform.OpenJSSEPlatform: can't find referenced class org.openjsse.net.ssl.OpenJSSE
okhttp3.internal.platform.android.Android10SocketAdapter: can't find referenced method 'java.lang.String getApplicationProtocol()' in library class javax.net.ssl.SSLSocket
okhttp3.internal.platform.android.Android10SocketAdapter: can't find referenced class android.net.ssl.SSLSockets
okhttp3.internal.platform.android.Android10SocketAdapter: can't find referenced method 'void setApplicationProtocols(java.lang.String[])' in library class javax.net.ssl.SSLParameters
okhttp3.internal.platform.android.BouncyCastleSocketAdapter: can't find referenced class org.bouncycastle.jsse.BCSSLParameters
okhttp3.internal.platform.android.BouncyCastleSocketAdapter: can't find referenced class org.bouncycastle.jsse.BCSSLSocket
okhttp3.internal.platform.android.BouncyCastleSocketAdapter$Companion$factory$1: can't find referenced class org.bouncycastle.jsse.BCSSLSocket
okhttp3.internal.platform.android.ConscryptSocketAdapter: can't find referenced class org.conscrypt.Conscrypt
okhttp3.internal.platform.android.ConscryptSocketAdapter$Companion$factory$1: can't find referenced class org.conscrypt.Conscrypt

Have we got any update on this bug?

All 21 comments

Can fix!

Yep, definitely not intended that we log this. My read is that under some conditions (proguard?) we can end up with conscrypt partially on the Android classpath, and it fails in a previously unobserved way. The logged exception is NoClassDefFoundError with a chained ClassNotFoundException.

But I have low certainty in this fix.

https://github.com/square/okhttp/pull/5763/files

Please reopen if this is still happening with the latest version

The error sill occurs with OkHttp 4.4.1.

I do not use conscrypt lib, but have to include it, if I do not then I am unable to perform any network calls. All the network calls from OKHttp fails. This fails in both emulator and real devices.
As a side effect, this lib also increased my app size to approx ~4 Mb

Can you post the failures? The logging is done by Android internals so it's hard to avoid but isn't expected to stop things working. Something else is going wrong in your app.

@rinav #5760 is discussing a functioning system which generates spam in the Android log. Please open a separate issue for this report of a functional defect. It is not the nature of #5760.

I do not use conscrypt lib, but have to include it, if I do not then I am unable to perform any network calls. All the network calls from OKHttp fails. This fails in both emulator and real devices.

@yschimke @jamesonwilliams
I created created a new issue as you suggested along with stack trace #5894

Hopefully fixed on 4.5. We can reopen if it's still happening. Otherwise, not sure what else to do, we don't control this logging and need to use Conscrypt util classes to cleanly detect whether it is installed correctly with native libs for platform.

The error sill occurs with OkHttp 4.5(Android Plugin 3.6.2 Gradle 6.3)

> Task :app:minifyReleaseWithR8
AGPBI: {"kind":"warning","text":"Missing class: org.conscrypt.ConscryptHostnameVerifier","sources":[{}],"tool":"R8"}

That's different. This bug is about spamming the error log at runtime. We can't avoid the problem you have raised without reverting to basically everything being done dynamically via reflection.

@yschimke ok, i see

Same bug, Android plugin 3.6.3, Logging Interceptor version 4.5.0

Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/conscrypt/ConscryptHostnameVerifier

Its still happening.

My Gradle config:

def retrofit_version = "2.8.1"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation("com.squareup.okhttp3:logging-interceptor:4.5.0")

I don't have a good solution for this currently. We need to detect presence of certain classes at runtime. Just doing this can cause this message and it's logged within Android, so we don't see this ourselves.

I had this issue only when i upgraded to 4.6.0, used to work correctly on 4.5.0

Same log spam with
okhttp:4.6.0
logging-interceptor:4.6.0
retrofit:2.8.1

Hi! Noticed the same logs for

versionRetrofit = '2.9.0'
versionOkHttp = '4.7.2'

Hopefully fixed (or minimised away from likely to occur in 4.8) when it's released.

Will reopen if still occurring then.

Hi! I just noticed that the error keeps occurring with OkHttp 4.8.1, along with other missing classes from bouncycastle, openjsse and android:

okhttp3.internal.platform.ConscryptPlatform$platformTrustManager$2: can't find superclass or interface org.conscrypt.ConscryptHostnameVerifier
okhttp3.internal.io.FileSystem$Companion$SYSTEM$1: can't find referenced class okhttp3.internal.io.FileSystem$DefaultImpls
okhttp3.internal.platform.BouncyCastlePlatform: can't find referenced class org.bouncycastle.jsse.BCSSLSocket
okhttp3.internal.platform.BouncyCastlePlatform: can't find referenced class org.bouncycastle.jsse.provider.BouncyCastleJsseProvider
okhttp3.internal.platform.BouncyCastlePlatform: can't find referenced class org.bouncycastle.jsse.BCSSLParameters
okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.ConscryptHostnameVerifier
okhttp3.internal.platform.ConscryptPlatform: can't find referenced class org.conscrypt.Conscrypt
okhttp3.internal.platform.ConscryptPlatform$Companion: can't find referenced class org.conscrypt.Conscrypt
okhttp3.internal.platform.ConscryptPlatform$platformTrustManager$2: can't find referenced class org.conscrypt.ConscryptHostnameVerifier
okhttp3.internal.platform.Jdk9Platform: can't find referenced method 'void setApplicationProtocols(java.lang.String[])' in library class javax.net.ssl.SSLParameters
okhttp3.internal.platform.Jdk9Platform: can't find referenced method 'java.lang.String getApplicationProtocol()' in library class javax.net.ssl.SSLSocket
okhttp3.internal.platform.OpenJSSEPlatform: can't find referenced class org.openjsse.javax.net.ssl.SSLParameters
okhttp3.internal.platform.OpenJSSEPlatform: can't find referenced class org.openjsse.javax.net.ssl.SSLSocket
okhttp3.internal.platform.OpenJSSEPlatform: can't find referenced class org.openjsse.net.ssl.OpenJSSE
okhttp3.internal.platform.android.Android10SocketAdapter: can't find referenced method 'java.lang.String getApplicationProtocol()' in library class javax.net.ssl.SSLSocket
okhttp3.internal.platform.android.Android10SocketAdapter: can't find referenced class android.net.ssl.SSLSockets
okhttp3.internal.platform.android.Android10SocketAdapter: can't find referenced method 'void setApplicationProtocols(java.lang.String[])' in library class javax.net.ssl.SSLParameters
okhttp3.internal.platform.android.BouncyCastleSocketAdapter: can't find referenced class org.bouncycastle.jsse.BCSSLParameters
okhttp3.internal.platform.android.BouncyCastleSocketAdapter: can't find referenced class org.bouncycastle.jsse.BCSSLSocket
okhttp3.internal.platform.android.BouncyCastleSocketAdapter$Companion$factory$1: can't find referenced class org.bouncycastle.jsse.BCSSLSocket
okhttp3.internal.platform.android.ConscryptSocketAdapter: can't find referenced class org.conscrypt.Conscrypt
okhttp3.internal.platform.android.ConscryptSocketAdapter$Companion$factory$1: can't find referenced class org.conscrypt.Conscrypt

Have we got any update on this bug?

Was this page helpful?
0 / 5 - 0 ratings