简体   繁体   English

在Android上使用Cognito用户池身份验证更正AWS AppSync的Proguard规则

[英]Correct Proguard Rules for AWS AppSync with Cognito User Pool Authentication on Android

I have an Android App using the AWS AppSync SDK with the following gradle configuration to connect to a cloud backend. 我有一个使用AWS AppSync SDK的Android应用程序,其中包含以下gradle配置以连接到云后端。

implementation 'com.amazonaws:aws-android-sdk-appsync:2.7.+'

Access to the backend resources is controlled via Cognito User Pools. 通过Cognito用户池控制对后端资源的访问。 User authentication and fetching data from the backend works fine without proguard enabled. 用户身份验证和从后端获取数据工作正常,无需启用proguard。 If I enable Proguard I get all sorts of warnings related to the AWS SDK. 如果我启用Proguard,我会收到与AWS SDK相关的各种警告。 The only way I managed to generate a signed APK with proguard enabled was by suppressing all AWS related warnings in the proguard-rules.pro like so: 我设法生成已启用proguard的签名APK的唯一方法是通过在proguard-rules.pro中抑制所有与AWS相关的警告,如下所示:

-dontwarn com.amazonaws.**

When I do this, the generated APK does not authenticate the user and data cannot be retrieved from the backend. 当我这样做时,生成的APK不会对用户进行身份验证,也无法从后端检索数据。 When I try to debug the APK, I get the following error in Android Studio: 当我尝试调试APK时,我在Android Studio中收到以下错误:

Could not connect to remote process. Aborting debug session.

Is there a more fine-grained proguard setting that gets rid of all the warnings but does not mess up the connection to the backend? 是否有更细粒度的proguard设置,摆脱所有的警告,但不会搞砸与后端的连接?

The following Proguard configuration did the trick for me: 以下Proguard配置为我做了诀窍:

-keepnames class com.amazonaws.**
-keepnames class com.amazon.**
# Request handlers defined in request.handlers
-keep class com.amazonaws.services.**.*Handler
# The following are referenced but aren't required to run
-dontwarn com.fasterxml.jackson.**
-dontwarn org.apache.commons.logging.**
# Android 6.0 release removes support for the Apache HTTP client
-dontwarn org.apache.http.**
# The SDK has several references of Apache HTTP client
-dontwarn com.amazonaws.http.**
-dontwarn com.amazonaws.metrics.**
-dontwarn com.amazonaws.mobile.**
-dontwarn com.amazonaws.mobileconnectors.**

All warnings disappear and the apk connects to the backend without any issues. 所有警告都消失,apk连接到后端没有任何问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM