简体   繁体   中英

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.

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

Access to the backend resources is controlled via Cognito User Pools. User authentication and fetching data from the backend works fine without proguard enabled. If I enable Proguard I get all sorts of warnings related to the 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:

-dontwarn com.amazonaws.**

When I do this, the generated APK does not authenticate the user and data cannot be retrieved from the backend. When I try to debug the APK, I get the following error in 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?

The following Proguard configuration did the trick for me:

-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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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