Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android and AWS Cognito - Unable to unmarshall error response with proguard

I am using the AWS cognito SDK for Android, version 2.4.3. It works perfectly fine on debug version, but on release versions, in case of error, I cannot get a proper description on the exception. Instead, I get this

com.amazonaws.AmazonClientException: Unable to unmarshall error response (<init> [class java.lang.String]). Response Code: 400, Response Text: Bad Request
    at com.amazonaws.http.AmazonHttpClient.a(Unknown Source)
    at com.amazonaws.http.AmazonHttpClient.b(Unknown Source)
    at com.amazonaws.http.AmazonHttpClient.a(Unknown Source)
    at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.a(Unknown Source)
    at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.a(Unknown Source)
    at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool.a(Unknown Source)
    at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool.a(Unknown Source)
    at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool$1.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NoSuchMethodException: <init> [class java.lang.String]
    at java.lang.Class.getConstructor(Class.java:531)
    at java.lang.Class.getConstructor(Class.java:495)
    at com.amazonaws.transform.AbstractErrorUnmarshaller.a(Unknown Source)
    at com.amazonaws.transform.JsonErrorUnmarshaller.b(Unknown Source)
    at com.amazonaws.services.cognitoidentityprovider.model.transform.InvalidParameterExceptionUnmarshaller.b(Unknown Source)
    at com.amazonaws.http.JsonErrorResponseHandler.a(Unknown Source)
    at com.amazonaws.http.JsonErrorResponseHandler.b(Unknown Source)
    at com.amazonaws.http.JsonErrorResponseHandler.a(Unknown Source)
    at com.amazonaws.http.AmazonHttpClient.a(Unknown Source) 
    at com.amazonaws.http.AmazonHttpClient.b(Unknown Source) 
    at com.amazonaws.http.AmazonHttpClient.a(Unknown Source) 
    at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.a(Unknown Source) 
    at com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient.a(Unknown Source) 
    at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool.a(Unknown Source) 
    at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool.a(Unknown Source) 
    at com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool$1.run(Unknown Source) 
    at java.lang.Thread.run(Thread.java:818) 

On debug version I get an exception indicating in detail the error. However, in both release and debug user registration succeeds in case all fields are well written. I am using proguard on release and I am aplying the rules from this file

Any help with this issue will be appreciated.

like image 740
Nicolás Arias Avatar asked May 26 '17 17:05

Nicolás Arias


2 Answers

After trying different Proguard settings, following is the minimal configuration, additional to that suggested on AWS SDK repository, to make it work

-keep class com.amazonaws.services.cognitoidentityprovider.** { *; }

it must be added to app/proguard-rules.pro

like image 81
Nicolás Arias Avatar answered Oct 23 '22 14:10

Nicolás Arias


Unmarshalling errors can also occur with classes in the AWS core library, not just com.amazonaws.services.cognitoidentityprovider. This rule will prevent this crash for all AWS lib exceptions:

-keep class * extends com.amazonaws.AmazonClientException { *; }
like image 3
Tom Avatar answered Oct 23 '22 16:10

Tom