Proguard configuration when using the Google Cloud Endpoints template for Android Studio Google

We need to store and receive the content that users generate using our application on the Internet. To do this, we decided to use the Android Studio integrated Google Cloud Endpoints template to quickly create an API (an official use case here ).

It works great when debugging, but in release mode, provided Proguard is turned on, it fails. Even worse, I did not find any documentation or samples about using Proguard with Android Studio Endpoints templates.

After an hour or so, to get out and try to get it to work, proguard-rules.pro now looks like this:

-keep class com.google.api.** { public *; } -dontwarn com.google.api.** -keep class com.google.common.** { public *; } -dontwarn com.google.common.** # Not allowed to post company and app names, but this line is correct in the real file -keep class com.companyname.appname.application.backend.** { *; } 

In this configuration, I get a class exception in my ArrayAdapter :

 java.lang.ClassCastException: com.google.api.client.util.ArrayMap cannot be cast to com.companyname.appname.application.backend.messageApi.model.Message 

It seems that the conversion of the returned data is not performed somewhere and instead of the List objects from Message , I get List objects from com.google.api.client.util.ArrayMap (they contain valid data, by the way).

I CAN check whether the application is in release mode and does the conversion manually, however this is a hacker approach and I would prefer to do it correctly. So, can someone please tell me what I am missing in the Proguard configuration file?

+5
source share
1 answer

I am doing similar things with endpoints in one of my applications. I had some problems with Proguard (I donโ€™t remember exactly what).

This section of my Proguard rules seems to apply:

 # Needed by google-api-client to keep generic types and @Key annotations accessed via reflection -keepclassmembers class * { @com.google.api.client.util.Key <fields>; } -keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault 

I do not know if this is necessary, but I also have this section:

 # Play Services -dontwarn com.google.android.gms.** -dontwarn com.google.common.cache.** -dontwarn com.google.common.primitives.** -keep class * extends java.util.ListResourceBundle { protected Object[][] getContents(); } -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable { public static final *** NULL; } -keepnames @com.google.android.gms.common.annotation.KeepName class * -keepclassmembernames class * { @com.google.android.gms.common.annotation.KeepName *; } 

Hope this helps.

+17
source

Source: https://habr.com/ru/post/1212336/


All Articles