Closed
Description
Describe the bug
Currently we are using the aws.sdk.kotlin:location to 1.3.62
and working as expected if are enforcing the OkHttp library
Regression Issue
- Select this option if this issue appears to be a regression.
Expected behavior
It supposed work with OKHttp4Engine
Current behavior
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/coroutines/ExecuteAsyncKt;
at aws.smithy.kotlin.runtime.http.engine.okhttp.OkHttpEngine.roundTrip(OkHttpEngine.kt:56)
at aws.smithy.kotlin.runtime.http.engine.internal.ManagedHttpClientEngine.roundTrip(Unknown Source:2)
at aws.smithy.kotlin.runtime.http.SdkHttpClient$executeWithCallContext$2.invokeSuspend(SdkHttpClient.kt:44)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:832)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)
Caused by: java.lang.ClassNotFoundException: Didn't find class "okhttp3.coroutines.ExecuteAsyncKt" on path: DexPathList[[dex file "/data/data/com.aws.testing/code_cache/.overlay/base.apk/classes13.dex", zip file "/data/app/~~pd18IQU0o1qsVUQG46H77Q==/com.aws.testing-jM1Bxk7yGtOSle0L-v5mlg==/base.apk"],nativeLibraryDirectories=[/data/app/~~pd18IQU0o1qsVUQG46H77Q==/com.aws.testing-jM1Bxk7yGtOSle0L-v5mlg==/lib/arm64, /data/app/~~pd18IQU0o1qsVUQG46H77Q==/com.aws.testing-jM1Bxk7yGtOSle0L-v5mlg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
at java.lang.ClassLoader.loadClass(ClassLoader.java:637)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
... 9 more
Steps to Reproduce
dependencies {
implementation ("software.amazon.location:auth:1.3.62")
implementation("aws.sdk.kotlin:location:0.2.5")
implementation("aws.smithy.kotlin:http-client-engine-okhttp4:1.3.12")
}
configurations.all {
resolutionStrategy {
force("com.squareup.okhttp3:okhttp:4.12.0")
}
exclude(group = "com.squareup.okhttp3", module = "okhttp-coroutines")
}
Code implementation
private var locationCredentialsProvider: LocationCredentialsProvider? = null
private var locationClient: LocationClient? = null
suspend fun getLocationClient(): LocationClient {
return runCatching {
if (locationClient == null) {
val poolId = configRepository.getRemoteConfigValue("***************************")
if (poolId != null) {
locationCredentialsProvider = AuthHelper(context).authenticateWithCognitoIdentityPool(poolId)
}
locationClient = locationCredentialsProvider?.getLocationClient() ?: error("CLIENT Location Client Retrieval failed")
locationClient!!.withConfig {
httpClient = OkHttp4Engine()
}
}
locationClient!!
}.getOrElse { e ->
e.printStackTrace()
error("COGNITO authentication failed")
}
}
Possible Solution
By changing the gradle config as follows to use the okhttp-coroutine:5.0.0-alpha.14 :
configurations.configureEach {
resolutionStrategy {
force("com.squareup.okhttp3:okhttp:4.12.0")
}
}
I just remove the exclude group: "com.squareup.okhttp3", module: "okhttp-coroutines"
Android app working as expected and my Dependency Graph looks like:
+--- com.squareup.okhttp3:okhttp-coroutines:{strictly 5.0.0-alpha.14} -> 5.0.0-alpha.14 (c)
| | +--- aws.smithy.kotlin:http-client-engine-default:1.3.17
| | | \--- aws.smithy.kotlin:http-client-engine-default-jvm:1.3.17
| | | +--- aws.smithy.kotlin:http-client:1.3.17 (*)
| | | +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 (*)
| | | +--- aws.smithy.kotlin:http-client-engine-okhttp:1.3.17
| | | | \--- aws.smithy.kotlin:http-client-engine-okhttp-jvm:1.3.17
| | | | +--- aws.smithy.kotlin:http-client:1.3.17 (*)
| | | | +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 (*)
| | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
| | | | +--- aws.smithy.kotlin:runtime-core:1.3.17 (*)
| | | | +--- aws.smithy.kotlin:telemetry-defaults:1.3.17
| | | | | \--- aws.smithy.kotlin:telemetry-defaults-jvm:1.3.17
| | | | | +--- aws.smithy.kotlin:telemetry-api:1.3.17 (*)
| | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 (*)
| | | | | +--- aws.smithy.kotlin:logging-slf4j2:1.3.17
| | | | | | \--- aws.smithy.kotlin:logging-slf4j2-jvm:1.3.17
| | | | | | +--- aws.smithy.kotlin:telemetry-api:1.3.17 (*)
| | | | | | +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.21 (*)
| | | | | | +--- org.slf4j:slf4j-api:2.0.16
| | | | | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
| | | | | \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
| | | | +--- com.squareup.okhttp3:okhttp:5.0.0-alpha.14 -> 4.12.0 (*)
| | | | \--- com.squareup.okhttp3:okhttp-coroutines:5.0.0-alpha.14
| | | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0 -> 1.9.0 (*)
| | | | +--- com.squareup.okhttp3:okhttp:5.0.0-alpha.14 -> 4.12.0 (*)
| | | | +--- com.squareup.okio:okio:3.9.0 -> 3.9.1 (*)
| | | | \--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.21 (*)
| | | +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
| | | \--- aws.smithy.kotlin:runtime-core:1.3.17 (*)
Context
I attempted to use okhttp-coroutine
from version 5.0.0-alpha.14
while enforcing Okhttp
version 4.12.0
, and it worked successfully. However, I'm uncertain of any potential consequences.
Smithy-Kotlin version
aws.sdk.kotlin:location :1.2.62
Platform (JVM/JS/Native)
JVM (Kotlin) JDK 17
Operating system and version
Android 13