Android和AWS Cognito - 无法使用proguard

时间:2017-05-26 17:39:59

标签: android aws-sdk amazon-cognito android-proguard

我正在使用适用于Android的AWS cognito SDK 2.4.3版。它在调试版本上运行得非常好,但在发布版本上,如果出现错误,我无法对异常进行正确的描述。相反,我得到了这个

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) 

在调试版本上,我得到一个异常,详细说明错误。但是,在发布和调试中,如果所有字段都写得很好,则用户注册成功。我在发布时使用proguard,我正在使用this file

中的规则

对此问题的任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:6)

尝试不同的Proguard设置后,以下是AWS SDK存储库建议的最小配置,以使其正常工作

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

必须将其添加到app/proguard-rules.pro

答案 1 :(得分:2)

AWS核心库中的类(不仅仅是com.amazonaws.services.cognitoidentityprovider)也可能发生解组错误。该规则将防止所有AWS lib异常的崩溃:

-keep class * extends com.amazonaws.AmazonClientException { *; }