Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Location Credentials Provider is failing #1411

Closed
1 task done
drayan85 opened this issue Sep 19, 2024 · 21 comments
Closed
1 task done

Location Credentials Provider is failing #1411

drayan85 opened this issue Sep 19, 2024 · 21 comments
Assignees
Labels
bug This issue is a bug. potential-regression Marking this issue as a potential regression to be checked by team member

Comments

@drayan85
Copy link

drayan85 commented Sep 19, 2024

Describe the bug

We are using Cognito pool ID in our Android Project to use the AWS location service.

When we try to create the LocationCredentialProvider (AuthHelper(context).authenticateWithCognitoIdentityPool(xxxx)) it is failing after 1.2.39 -> 1.3.34 with the following error:
java.lang.NoClassDefFoundError: aws.sdk.kotlin.services.cognitoidentity.endpoints.internal.PartitionsKt

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected behavior

It should successfully return the LocationCredentialsProvider object

Current behavior

Throwing Exception:

java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Boolean;Ljava/lang/Boolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)
V in class Laws/sdk/kotlin/runtime/endpoint/functions/PartitionConfig; or its super classes (declaration of 'aws.sdk.kotlin.runtime.endpoint.functions.PartitionConfig' 
appears in /data/app/~~S8m3JjDNTe7asB6VD3qQwA==/com.android-aws-location-A2tHD-m82ib5570DnPQ5Eg==/base.apk!classes20.dex)

Steps to Reproduce

Location demo app was working as expected when aws.sdk.kotlin:location => 1.2.38 and just updating this to 1.2.39 in the gradle configuration started get this exception.
FYI, We are not forcing the OKHTTP3 library to downgrade (Some other issue mentioning that this exception is occurred when they force downgrade to OkHttp3 to 4.x verion )

Possible Solution

Currently we are downgraded the aws.sdk.kotlin:location to 1.2.38 and working as expected.

Exception started inside the LocationCredentialsProvider -> val getIdResponse = cognitoIdentityClient?.getId(GetIdRequest { this.identityPoolId = identityPoolId })

    private suspend fun generateCredentials(region: String, identityPoolId: String) {
        if (cognitoIdentityClient == null) {
            cognitoIdentityClient = generateCognitoIdentityClient(region)
        }
        try {
            val getIdResponse = cognitoIdentityClient?.getId(GetIdRequest { this.identityPoolId = identityPoolId })
            val identityId =
                getIdResponse?.identityId ?: throw Exception("Failed to get identity ID")
            if (identityId.isNotEmpty()) {
                val getCredentialsResponse =
                    cognitoIdentityClient?.getCredentialsForIdentity(GetCredentialsForIdentityRequest {
                        this.identityId = identityId
                    })

                val credentials = getCredentialsResponse?.credentials
                    ?: throw Exception("Failed to get credentials")
                if (credentials.accessKeyId == null || credentials.secretKey == null || credentials.sessionToken == null) throw Exception(
                    "Credentials generation failed"
                )
                cognitoCredentialsProvider = CognitoCredentialsProvider(
                    context,
                    identityId,
                    credentials
                )
                locationClient = null
            }
        } catch (e: Exception) {
            throw Exception("Credentials generation failed")
        }
    }

Context

We are far away from the latest of the library in our production app and also concern about using not stable OkHttp3 (5.0.0-alpha.14) library which will override by the AWS library (transient dependency) in our production app

AWS SDK for Kotlin version

1.2.38 - 1.3.34

Platform (JVM/JS/Native)

JVM (Kotlin)

Operating system and version

Android 13

@drayan85 drayan85 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 19, 2024
@github-actions github-actions bot added the potential-regression Marking this issue as a potential regression to be checked by team member label Sep 19, 2024
@0marperez
Copy link
Contributor

0marperez commented Sep 23, 2024

Hi, thanks for the report. It looks like your issue might be caused by a versioning conflict in these two versions of the SDK that are not compatible (1.2.39 & 1.2.21). Versions labelled 1.2.x should be compatible with each other but it seems like there might be an issue here. We'll be working on a fix.

In regards to your concern with using an alpha version of OkHttp 3 we have created an http engine for this that uses OkHttp 4.x. You can look at the readme here

@drayan85
Copy link
Author

drayan85 commented Sep 24, 2024

But We could not find a way to add the okHttp4Engine in the android location library to enforce the OkHttp Engine.

Could you please guide us where we can find documentation or sample code snippet that we can use ?

@0marperez
Copy link
Contributor

Sure, here's an example of how you could use it

Your build.gradle file:

dependencies {
    implementation("aws.sdk.kotlin:location:$SDK_VERSION") // and any other AWS SDK clients... 
    implementation("aws.smithy.kotlin:http-client-engine-okhttp4:$SMITHY_KOTLIN_VERSION") // depend on OkHttp4Engine
}

configurations.all {
    resolutionStrategy {
        // Force resolve to OkHttp 4.x
        force("com.squareup.okhttp3:okhttp:4.12.0") // or whichever version you are using... 
    }
    exclude(group = "com.squareup.okhttp3", module = "okhttp-coroutines") // Exclude dependency on okhttp-coroutines, which is introduced in 5.0.0-alpha.X 
}

Your code:

import aws.sdk.kotlin.services.location.LocationClient
import aws.smithy.kotlin.runtime.http.engine.okhttp4.OkHttp4Engine
OkHttp4Engine().use { okHttp4Engine ->
    LocationClient {
        httpClient = okHttp4Engine
    }.use {
        // Your operation `it.listKeys {}` for example
    }
}

@0marperez 0marperez removed the needs-triage This issue or PR still needs to be triaged. label Sep 24, 2024
@drayan85
Copy link
Author

In our case we are using AWS Location auth library as well.

dependencies {
    implementation ("software.amazon.location:auth:$AUTH_VERSION")
    implementation("aws.sdk.kotlin:location:$SDK_VERSION") // and any other AWS SDK clients... 
    implementation("aws.smithy.kotlin:http-client-engine-okhttp4:$SMITHY_KOTLIN_VERSION") // depend on OkHttp4Engine
}

configurations.all {
    resolutionStrategy {
        // Force resolve to OkHttp 4.x
        force("com.squareup.okhttp3:okhttp:4.12.0") // or whichever version you are using... 
    }
    exclude(group = "com.squareup.okhttp3", module = "okhttp-coroutines") // Exclude dependency on okhttp-coroutines, which is introduced in 5.0.0-alpha.X 
}

In our Code:

val locationCredentialsProvider: LocationCredentialsProvider = 
                       AuthHelper(context).authenticateWithCognitoIdentityPool("xxxxxxxxxx")
val locationClient: LocationClient = locationCredentialsProvider.getLocationClient()
val request = SearchPlaceIndexForSuggestionsRequest {
      text = "sydney"
      indexName = "xxxxx"
}
val response = locationClient.searchPlaceIndexForSuggestions(request)

Since we are get the authorised client via LocationCredentialProvider, How do I initiate the authorisation using our dedicated Cognito Pool ID and Places Index if I received the Location client as you suggested follow:

OkHttp4Engine().use { okHttp4Engine ->
    LocationClient {
        httpClient = okHttp4Engine
    }.use { locationClient ->
       val request = SearchPlaceIndexForSuggestionsRequest {
          text = "sydney"
          indexName = "xxxxx"
        }
        val response = locationClient.searchPlaceIndexForSuggestions(request)
    }
}

@drayan85
Copy link
Author

drayan85 commented Oct 3, 2024

Any update on forcing the OkHttp4Engine, LocationClient with Cognito Pool ID authorisation ?

@lauzadis
Copy link
Member

lauzadis commented Oct 3, 2024

You will want to override the client configuration of the LocationClient returned from locationCredentialsProvider.getLocationClient() using withConfig { ... }. See our developer guide for details: https://docs.aws.amazon.com/sdk-for-kotlin/latest/developer-guide/override-client-config.html

It will look something like this:

val locationCredentialsProvider: LocationCredentialsProvider = AuthHelper(context).authenticateWithCognitoIdentityPool("xxxxxxxxxx")

val locationClient: LocationClient = locationCredentialsProvider.getLocationClient()

val okHttp4Engine = OkHttp4Engine()

val overriddenLocationClient = locationClient.withConfig {
    httpClient = okHttp4Engine
}

val request = SearchPlaceIndexForSuggestionsRequest {
      text = "sydney"
      indexName = "xxxxx"
}

val response = locationClient.searchPlaceIndexForSuggestions(request)

// Make sure to close all clients and engines when you are done using them
overriddenLocationClient.close()
okHttp4Engine.close()
locationClient.close()

@drayan85
Copy link
Author

drayan85 commented Oct 4, 2024

Thanks @lauzadis for the info.

But still we are stuck with the following error:
at aws.sdk.kotlin.services.cognitoidentity.endpoints.internal.PartitionsKt.<clinit>(Partitions.kt:18)

Hopefully when #1415 get merge we should be able to upgrade aws.sdk.kotlin:location to the latest version

@drayan85
Copy link
Author

drayan85 commented Oct 8, 2024

I greatly appreciate your prompt assistance in resolving this issue, as it will allow us to address the user crashes in our production app.

@drayan85
Copy link
Author

After enforcing the OkHttpEngine, I am getting the following error with aws.sdk.kotlin:location:1.2.38. 🤔

Failed resolution of: Lokhttp3/coroutines/ExecuteAsyncKt;
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:4)
  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.sample.android.staging/code_cache/.overlay/base.apk/classes20.dex", dex file "/data/data/com.sample.android.staging/code_cache/.overlay/base.apk/classes21.dex", dex file "/data/data/com.sample.android.staging/code_cache/.overlay/base.apk/classes5.dex", zip file "/data/app/~~8WrdXpybi6Us0e9DVUgyJw==/com.sample.android.staging-MeyNaro4A0eEZStNMIJl9A==/base.apk"],nativeLibraryDirectories=[/data/app/~~8WrdXpybi6Us0e9DVUgyJw==/com.sample.android.staging-MeyNaro4A0eEZStNMIJl9A==/lib/arm64, /data/app/~~8WrdXpybi6Us0e9DVUgyJw==/com.sample.android.staging-MeyNaro4A0eEZStNMIJl9A==/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:379)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
  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:4) 
  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) 

@lauzadis
Copy link
Member

That error suggests to me that you still have OkHttp 5.x in your dependencies somewhere. Can you please run ./gradlew dependencies for each of your modules and see if com.squareup.okhttp3:okhttp:5.0.0-alpha.14 shows up?

@drayan85
Copy link
Author

implementation - Implementation only dependencies for 'main' sources. (n)
+--- project ui (n)
+--- aws.sdk.kotlin:location:1.2.38 (n)
+--- software.amazon.location:auth:0.2.5 (n)
+--- aws.smithy.kotlin:http-client-engine-okhttp4:1.3.12 (n)
+--- javax.annotation:javax.annotation-api:1.3.2 (n)
+--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20 (n)
+--- org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.2 (n)
+--- com.squareup.okhttp3:okhttp:4.12.0 (n)
+--- com.squareup.okhttp3:logging-interceptor:4.12.0 (n)
+--- com.google.android.play:review:2.0.1 (n)
+--- com.google.android.play:review-ktx:2.0.1 (n)
+--- com.squareup.retrofit2:retrofit:2.11.0 (n)
+--- com.squareup.retrofit2:converter-gson:2.11.0 (n)
+--- com.squareup.retrofit2:adapter-rxjava2:2.11.0 (n)
+--- com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0 (n)
\--- androidx.tracing:tracing:1.2.0 (n)
+--- aws.sdk.kotlin:location:1.2.38
|    \--- aws.sdk.kotlin:location-jvm:1.2.38
|         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         +--- aws.sdk.kotlin:aws-config:1.2.38
|         |    \--- aws.sdk.kotlin:aws-config-jvm:1.2.38
|         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         +--- aws.sdk.kotlin:aws-core:1.2.38
|         |         |    \--- aws.sdk.kotlin:aws-core-jvm:1.2.38
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12
|         |         |         |    \--- aws.smithy.kotlin:runtime-core-jvm:1.3.12
|         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |         |         \--- com.squareup.okio:okio:3.9.0 (*)
|         |         |         \--- aws.smithy.kotlin:smithy-client:1.2.7 -> 1.3.12
|         |         |              \--- aws.smithy.kotlin:smithy-client-jvm:1.3.12
|         |         |                   +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |                   +--- aws.smithy.kotlin:runtime-core:1.3.12 (*)
|         |         |                   +--- aws.smithy.kotlin:identity-api:1.3.12
|         |         |                   |    \--- aws.smithy.kotlin:identity-api-jvm:1.3.12
|         |         |                   |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |                   |         +--- aws.smithy.kotlin:runtime-core:1.3.12 (*)
|         |         |                   |         +--- aws.smithy.kotlin:telemetry-api:1.3.12
|         |         |                   |         |    \--- aws.smithy.kotlin:telemetry-api-jvm:1.3.12
|         |         |                   |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |                   |         |         +--- aws.smithy.kotlin:runtime-core:1.3.12 (*)
|         |         |                   |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |                   |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |                   \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         +--- aws.smithy.kotlin:aws-credentials:1.2.7
|         |         |    \--- aws.smithy.kotlin:aws-credentials-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:identity-api:1.2.7 -> 1.3.12 (*)
|         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         |         \--- aws.smithy.kotlin:telemetry-api:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12
|         |         |    \--- aws.smithy.kotlin:http-client-jvm:1.3.12
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:runtime-core:1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:smithy-client:1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:http:1.3.12
|         |         |         |    \--- aws.smithy.kotlin:http-jvm:1.3.12
|         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         |         +--- aws.smithy.kotlin:runtime-core:1.3.12 (*)
|         |         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |         |         \--- aws.smithy.kotlin:telemetry-api:1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:http-auth:1.3.12
|         |         |         |    \--- aws.smithy.kotlin:http-auth-jvm:1.3.12
|         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         |         +--- aws.smithy.kotlin:runtime-core:1.3.12 (*)
|         |         |         |         +--- aws.smithy.kotlin:http:1.3.12 (*)
|         |         |         |         +--- aws.smithy.kotlin:http-auth-api:1.3.12
|         |         |         |         |    \--- aws.smithy.kotlin:http-auth-api-jvm:1.3.12
|         |         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:identity-api:1.3.12 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:http:1.3.12 (*)
|         |         |         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |         \--- aws.smithy.kotlin:telemetry-api:1.3.12 (*)
|         |         +--- aws.smithy.kotlin:http:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.smithy.kotlin:http-auth:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.smithy.kotlin:telemetry-api:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.smithy.kotlin:http-client-engine-default:1.2.7
|         |         |    \--- aws.smithy.kotlin:http-client-engine-default-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:http-client-engine-okhttp:1.2.7 -> 1.3.12
|         |         |         |    \--- aws.smithy.kotlin:http-client-engine-okhttp-jvm:1.3.12
|         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         |         +--- aws.smithy.kotlin:http-client:1.3.12 (*)
|         |         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0 (*)
|         |         |         |         +--- aws.smithy.kotlin:runtime-core:1.3.12 (*)
|         |         |         |         +--- aws.smithy.kotlin:telemetry-defaults:1.3.12
|         |         |         |         |    \--- aws.smithy.kotlin:telemetry-defaults-jvm:1.3.12
|         |         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:telemetry-api:1.3.12 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:logging-slf4j2:1.3.12
|         |         |         |         |         |    \--- aws.smithy.kotlin:logging-slf4j2-jvm:1.3.12
|         |         |         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:2.0.10 -> 2.0.20 (*)
|         |         |         |         |         |         +--- aws.smithy.kotlin:telemetry-api:1.3.12 (*)
|         |         |         |         |         |         +--- org.slf4j:slf4j-api:2.0.9 -> 2.0.12
|         |         |         |         |         |         \--- 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 (*)
|         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         |         \--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.sdk.kotlin:aws-http:1.2.38
|         |         |    \--- aws.sdk.kotlin:aws-http-jvm:1.2.38
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.sdk.kotlin:aws-core:1.2.38 (*)
|         |         |         +--- aws.sdk.kotlin:aws-endpoint:1.2.38
|         |         |         |    \--- aws.sdk.kotlin:aws-endpoint-jvm:1.2.38
|         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         |         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12 (*)
|         |         |         |         +--- aws.smithy.kotlin:aws-signing-common:1.2.7
|         |         |         |         |    \--- aws.smithy.kotlin:aws-signing-common-jvm:1.2.7
|         |         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:aws-credentials:1.2.7 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:http-auth:1.2.7 -> 1.3.12 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:http:1.2.7 -> 1.3.12 (*)
|         |         |         |         |         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12 (*)
|         |         |         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         |         |         \--- aws.sdk.kotlin:aws-core:1.2.38 (*)
|         |         |         +--- aws.smithy.kotlin:aws-signing-common:1.2.7 (*)
|         |         |         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12 (*)
|         |         |         \--- aws.smithy.kotlin:http-auth-aws:1.2.7
|         |         |              \--- aws.smithy.kotlin:http-auth-aws-jvm:1.2.7
|         |         |                   +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |                   +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         |                   +--- aws.smithy.kotlin:http:1.2.7 -> 1.3.12 (*)
|         |         |                   +--- aws.smithy.kotlin:http-auth-api:1.2.7 -> 1.3.12 (*)
|         |         |                   +--- aws.smithy.kotlin:aws-signing-common:1.2.7 (*)
|         |         |                   \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         +--- aws.smithy.kotlin:serde-json:1.2.7
|         |         |    \--- aws.smithy.kotlin:serde-json-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:serde:1.2.7
|         |         |         |    \--- aws.smithy.kotlin:serde-jvm:1.2.7
|         |         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         |         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         +--- aws.smithy.kotlin:aws-protocol-core:1.2.7
|         |         |    \--- aws.smithy.kotlin:aws-protocol-core-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:http:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:smithy-client:1.2.7 -> 1.3.12 (*)
|         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         +--- aws.smithy.kotlin:aws-signing-common:1.2.7 (*)
|         |         +--- aws.smithy.kotlin:aws-signing-default:1.2.7
|         |         |    \--- aws.smithy.kotlin:aws-signing-default-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:aws-signing-common:1.2.7 (*)
|         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         +--- aws.smithy.kotlin:http-auth-aws:1.2.7 (*)
|         |         +--- aws.smithy.kotlin:identity-api:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.smithy.kotlin:serde:1.2.7 (*)
|         |         +--- aws.smithy.kotlin:smithy-client:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.smithy.kotlin:telemetry-defaults:1.2.7 -> 1.3.12 (*)
|         |         +--- aws.sdk.kotlin:aws-endpoint:1.2.38 (*)
|         |         +--- aws.smithy.kotlin:serde-xml:1.2.7
|         |         |    \--- aws.smithy.kotlin:serde-xml-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:serde:1.2.7 (*)
|         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         +--- aws.smithy.kotlin:serde-form-url:1.2.7
|         |         |    \--- aws.smithy.kotlin:serde-form-url-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:serde:1.2.7 (*)
|         |         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         +--- aws.smithy.kotlin:aws-xml-protocols:1.2.7
|         |         |    \--- aws.smithy.kotlin:aws-xml-protocols-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:http:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         |         +--- aws.smithy.kotlin:aws-protocol-core:1.2.7 (*)
|         |         |         +--- aws.smithy.kotlin:serde:1.2.7 (*)
|         |         |         \--- aws.smithy.kotlin:serde-xml:1.2.7 (*)
|         |         +--- aws.smithy.kotlin:aws-json-protocols:1.2.7
|         |         |    \--- aws.smithy.kotlin:aws-json-protocols-jvm:1.2.7
|         |         |         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.23 -> 2.0.20 (*)
|         |         |         +--- aws.smithy.kotlin:smithy-client:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12 (*)
|         |         |         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         |         |         +--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         |         |         +--- aws.smithy.kotlin:aws-protocol-core:1.2.7 (*)
|         |         |         +--- aws.smithy.kotlin:serde:1.2.7 (*)
|         |         |         \--- aws.smithy.kotlin:serde-json:1.2.7 (*)
|         |         \--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 -> 1.9.0 (*)
|         +--- aws.sdk.kotlin:aws-core:1.2.38 (*)
|         +--- aws.sdk.kotlin:aws-endpoint:1.2.38 (*)
|         +--- aws.smithy.kotlin:http-client:1.2.7 -> 1.3.12 (*)
|         +--- aws.smithy.kotlin:runtime-core:1.2.7 -> 1.3.12 (*)
|         +--- aws.smithy.kotlin:smithy-client:1.2.7 -> 1.3.12 (*)
|         +--- aws.smithy.kotlin:telemetry-api:1.2.7 -> 1.3.12 (*)
|         +--- aws.smithy.kotlin:aws-credentials:1.2.7 (*)
|         +--- aws.sdk.kotlin:aws-http:1.2.38 (*)
|         +--- aws.smithy.kotlin:aws-json-protocols:1.2.7 (*)
|         +--- aws.smithy.kotlin:aws-protocol-core:1.2.7 (*)
|         +--- aws.smithy.kotlin:aws-signing-common:1.2.7 (*)
|         +--- aws.smithy.kotlin:aws-signing-default:1.2.7 (*)
|         +--- aws.smithy.kotlin:http:1.2.7 -> 1.3.12 (*)
|         +--- aws.smithy.kotlin:http-auth:1.2.7 -> 1.3.12 (*)
|         +--- aws.smithy.kotlin:http-auth-aws:1.2.7 (*)
|         +--- aws.smithy.kotlin:http-client-engine-default:1.2.7 (*)
|         +--- aws.smithy.kotlin:identity-api:1.2.7 -> 1.3.12 (*)
|         +--- org.jetbrains.kotlin:kotlin-stdlib:1.9.21 -> 2.0.20 (*)
|         +--- aws.smithy.kotlin:serde:1.2.7 (*)
|         +--- aws.smithy.kotlin:serde-json:1.2.7 (*)
|         \--- aws.smithy.kotlin:telemetry-defaults:1.2.7 -> 1.3.12 (*)

@drayan85
Copy link
Author

I can see okhttp version has been forced com.squareup.okhttp3:okhttp:5.0.0-alpha.14 -> 4.12.0 (*)

@ianbotsf
Copy link
Contributor

It's possible your client initialization code may still be trying to use the default (OkHttp 5) engine and failing because the OkHttp 4 engine is the only one on the class path. Can you please share the code where you initialize your LocationClient? It should ideally look something like described in the module docs.

@ianbotsf ianbotsf self-assigned this Oct 15, 2024
@ianbotsf
Copy link
Contributor

@drayan85 Can you confirm if you're still seeing the NoClassDefFoundError with the OkHttp 4 engine configured? If so, can you share the code where you initialize the LocationClient?

@ianbotsf ianbotsf added the response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. label Oct 15, 2024
@drayan85
Copy link
Author

drayan85 commented Oct 15, 2024

Yes, still when we try access location service end points we are getting the error

fun getAWSLocationClinent(): LocationClient {
    val locationCredentialsProvider: LocationCredentialsProvider = 
    AuthHelper(context).authenticateWithCognitoIdentityPool("xxxxxxxxxx") 
    val locationClient: LocationClient = locationCredentialsProvider.getLocationClient()
    return locationClient.withConfig { 
                httpClient = okHttp4Engine ()
           }
}

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. label Oct 16, 2024
@ianbotsf
Copy link
Contributor

A fix for this was released today in SDK version 1.3.60. Can you retry with the latest version of the Location client and let me know if the problem is resolved?

@0marperez 0marperez added the closing-soon This issue will automatically close in 2 days unless further comments are made. label Oct 29, 2024
@ianbotsf
Copy link
Contributor

Any update on SDK versions 1.3.60 or later @drayan85?

@ianbotsf ianbotsf added response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. and removed response-requested Waiting on additional info and feedback. Will move to 'closing-soon' in 5 days. labels Oct 29, 2024
@github-actions github-actions bot removed the closing-soon This issue will automatically close in 2 days unless further comments are made. label Oct 29, 2024
@drayan85
Copy link
Author

Yes, We have updated to the 1.3.62 and working as expected if we don't not enforce the OkHttp4Engine to the LocationClient. If we enforce then we are getting the same error as before:

In the Gradle file

configurations.configureEach {
    resolutionStrategy {
        force("com.squareup.okhttp3:okhttp:4.12.0") // Force resolve to OkHttp 4.x
    }
    exclude group: "com.squareup.okhttp3", module: "okhttp-coroutines" // Exclude dependency on okhttp-coroutines, which is introduced in 5.0.0-alpha.X
}

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(Config.AWS_COGNITO_IDENTITY_POOL_ID)
        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")
    }
  }
  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

@drayan85
Copy link
Author

drayan85 commented Oct 30, 2024

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.

BBy 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 (*)

@lauzadis
Copy link
Member

If v1.3.62 is working for you without configuring OkHttp4Engine, do that, it's the preferred option. OkHttp v4.x is an older major version and we created that engine to support people stuck on it.

It sounds like you've got a few working solutions, so I'll be closing this issue. Please reach out if you have further problems!

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. potential-regression Marking this issue as a potential regression to be checked by team member
Projects
None yet
Development

No branches or pull requests

4 participants