From 330ed1e00aa788a8af95e88aea1c24701ed1cf3e Mon Sep 17 00:00:00 2001 From: Leonid Stashevsky Date: Mon, 17 Sep 2018 12:40:05 +0300 Subject: [PATCH] Fix client service loader on the android --- .../src/io/ktor/client/HttpClientJvm.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ktor-client/ktor-client-core/ktor-client-core-jvm/src/io/ktor/client/HttpClientJvm.kt b/ktor-client/ktor-client-core/ktor-client-core-jvm/src/io/ktor/client/HttpClientJvm.kt index 0f92b69d3df..9af47d2606f 100644 --- a/ktor-client/ktor-client-core/ktor-client-core-jvm/src/io/ktor/client/HttpClientJvm.kt +++ b/ktor-client/ktor-client-core/ktor-client-core-jvm/src/io/ktor/client/HttpClientJvm.kt @@ -13,7 +13,12 @@ interface HttpClientEngineContainer { val factory: HttpClientEngineFactory<*> } -private val FACTORY = ServiceLoader.load(HttpClientEngineContainer::class.java) - .toList() - .firstOrNull() - ?.factory ?: error("Failed to find HttpClientEngineContainer in classpath via ServiceLoader") \ No newline at end of file +/** + * Workaround for dummy android [ClassLoader]. + */ +private val engines: List = HttpClientEngineContainer::class.java.let { + ServiceLoader.load(it, it.classLoader).toList() +} + +private val FACTORY = engines.firstOrNull()?.factory + ?: error("Failed to find HttpClientEngineContainer in classpath via ServiceLoader") \ No newline at end of file