久々にKotlinでokhttp3を使ったらいきなり落ちたのでメモ。
Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/conscrypt/ConscryptHostnameVerifier;
val client = OkHttpClient() // ここで落ちる
val request = Request.Builder()
.url("https://...")
.build()
client.newCall(request).enqueue(object : okhttp3.Callback {
@Throws(IOException::class)
override fun onResponse(call: Call, response: Response) {
// .....
}
override fun onFailure(call: Call, arg1: IOException) {
// ....
}
})
対処
okhttp自体のバージョンを下げることで一旦対応。
dependencies {
// ....
// implementation 'com.squareup.okhttp3:okhttp:4.4.0'
implementation 'com.squareup.okhttp3:okhttp:4.0.0'
}
org.conscrypt:conscrypt-android をimplementationするようにという文献もありましたが、本来conscryptはokhttp3にとってoptionでありokhttp側のバグと考えられるので一旦この方法で様子を見ることに。
本家GitHubのIssue
OkHttp 4.3.1 spams log, didn’t find class “org.conscrypt.ConscryptHostnameVerifier” on path #5760
2020/05/28 更新:BugのLabelがついている。まだOpen。
2020/10/14 更新:4.8で解決しそうということでcloseされている。