You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What happened and how can we reproduce this issue?
Hello. When I invoke Ktorfit.Builder() I get a crash on Xiaomi.
Caused by java.lang.IllegalStateException: Failed to find HTTP client engine implementation in the classpath: consider adding client engine dependency. See https://ktor.io/docs/http-client-engines.html
at io.ktor.client.HttpClientJvmKt.<clinit>(HttpClientJvm.kt:43)
at io.ktor.client.HttpClientJvmKt.b(HttpClientJvm.kt:1)
at de.jensklingenberg.ktorfit.Ktorfit$Builder.<init>(Ktorfit.kt:50)
at ru.cian.base.kmm.impl.network.BaseNetworkModuleKt$baseNetworkModule$1$2.invoke(BaseNetworkModule.kt:53)
.....
What did you expect to happen?
No crash)
Is there anything else we need to know about?
I create Ktorfit.Builder with getting a HttpClient from Koin. Like this:
Caused by java.lang.IllegalStateException: Failed to find HTTP client engine implementation in the classpath: consider adding client engine dependency. See https://ktor.io/docs/http-client-engines.html
at io.ktor.client.HttpClientJvmKt.<clinit>(HttpClientJvm.kt:43)
at io.ktor.client.HttpClientJvmKt.b(HttpClientJvm.kt:1)
at de.jensklingenberg.ktorfit.Ktorfit$Builder.<init>(Ktorfit.kt:50)
at ru.cian.base.kmm.impl.network.BaseNetworkModuleKt$baseNetworkModule$1$2.invoke(BaseNetworkModule.kt:53)
.....
This crash only appears on Xiaomi devices with Android 12 and 13. Other devices is OK.
I found a cause. When Ktorfit.Builder() is called, one of its fields calls the HttpClient() constructor with no arguments.
public class Builder {
private var _baseUrl: String = ""
private var _httpClient = HttpClient()
....
In HttpClientKvm this crash appears when Ktor can't find any HttpClientEngineContainer in ClassLoader.
private val engines: List<HttpClientEngineContainer> = HttpClientEngineContainer::class.java.let {
ServiceLoader.load(it, it.classLoader).toList()
}
private val FACTORY = engines.firstOrNull()?.factory ?: error(
"Failed to find HTTP client engine implementation in the classpath: consider adding client engine dependency. " +
"See https://ktor.io/docs/http-client-engines.html"
)
My hypothesis is that Xiaomi has a bug in custom ClassLoader. It cannot load OkHttp until the Koin method to create the HttpClient is called.
In my app now, I create an HttpClient before invoking Ktorfit.Builder(). Like this:
val httpClient = get<HttpClient>()
Ktorfit.Builder()
.baseUrl(baseUrl)
.httpClient(httpClient)
.build()
I think, need to remove the HttpClient creation in the Ktorfit.Builder field as it causes a crash. In addition, an extra HttpClient instance will not be created if I use a custom HttpClient
The text was updated successfully, but these errors were encountered:
Ktorfit version
1.4.2
What happened and how can we reproduce this issue?
Hello. When I invoke Ktorfit.Builder() I get a crash on Xiaomi.
What did you expect to happen?
No crash)
Is there anything else we need to know about?
I create Ktorfit.Builder with getting a HttpClient from Koin. Like this:
In the release app users get a crash:
But I always create a HttpClient with an engine
This crash only appears on Xiaomi devices with Android 12 and 13. Other devices is OK.
I found a cause. When Ktorfit.Builder() is called, one of its fields calls the HttpClient() constructor with no arguments.
In HttpClientKvm this crash appears when Ktor can't find any HttpClientEngineContainer in ClassLoader.
My hypothesis is that Xiaomi has a bug in custom ClassLoader. It cannot load OkHttp until the Koin method to create the HttpClient is called.
In my app now, I create an HttpClient before invoking Ktorfit.Builder(). Like this:
I think, need to remove the HttpClient creation in the Ktorfit.Builder field as it causes a crash. In addition, an extra HttpClient instance will not be created if I use a custom HttpClient
The text was updated successfully, but these errors were encountered: