aws-sdk-kotlin: Location Credentials Provider is failing

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

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