使用Android Studio的Google Cloud Endpoints模板时的Proguard配置 [英] Proguard configuration when using Android Studio's Google Cloud Endpoints template

查看:173
本文介绍了使用Android Studio的Google Cloud Endpoints模板时的Proguard配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要存储和检索用户在线生成的内容。为此,我们决定使用Android Studio的集成Google Cloud Endpoints模板快速创建API(官方使用示例

它在调试中可以正常工作,但在释放模式下,启用Proguard时,它会失败。更糟糕的是,我没有找到任何关于在Android Studio的Endpoints模板中使用Proguard的文档或示例。



经过一小时左右的时间,试图制作它正常工作,现在 proguard-rules.pro 看起来像这样:

  -keep class com。 google.api。** {public *; } 
-twtwarn com.google.api。**
-keep class com.google.common。** {public *;} }
-dontwarn com.google.common。**

#不允许发布公司名称和应用程序名称,但是这一行在真实文件中是正确的
-keep class com .companyname.appname.application.backend。** {*; }

使用这个配置,我在 ArrayAdapter

  java.lang.ClassCastException:com.google.api.client.util.ArrayMap无法转换为com.companyname.appname.application.backend.messageApi.model.Message 

看来返回数据的转换不是在某处执行的,而是 Message 对象的 List ,我得到一个 List > com.google.api.client.util.ArrayMap 对象(顺便说一句,它们确实包含有效数据) 。

我可以检查应用程序是否在发布模式下运行,并手动进行转换,但是,这是一种很冒险的方式,我宁愿正确地做。所以,有人能告诉我我在Proguard配置文件中缺少什么吗?

解决方案

我的一个应用程序。我也遇到了Proguard的一些问题(不记得具体是什么)。



我的Proguard规则的这一部分似乎适用:

 #需要google-api-client保留通过反射访问的泛型类型和@Key注释
-keepclassmembers类* {
@com。 google.api.client.util.Key< fields> ;;
}
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault

我不知道如果有必要,但我也有这部分内容:

 #Play Services 
-twtwarn 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 *;
}

希望它有帮助。


We need to store and retrieve the content that users generate with our app online. To do so, we decided to use Android Studio's integrated Google Cloud Endpoints template to quickly create an API (official usage example here).

It works fine in debug, but in release mode, with Proguard enabled, it fails. Worse still, I've failed to find any documentation or samples about using Proguard with the Android Studio's Endpoints templates.

After an hour or so of poking around and trying to make it work, the 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.** { *; }

With this configuration, I'm getting a class cast 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 the conversion of returned data isn't performed somewhere and, instead of a List of Message objects, I get a List of com.google.api.client.util.ArrayMap objects (they do contain valid data, by the way).

I COULD check whether the app is running in release mode and do the conversion manually, however, it's a hacky way and I'd prefer to do it properly. So, can someone please tell me what I'm missing in the Proguard configuration file?

解决方案

I do similar things with endpoints in one of my apps. I had some problems with Proguard as well (can't remember exactly what).

This section of my Proguard rules seems applicable:

# 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 don't know if it 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 it helps.

这篇关于使用Android Studio的Google Cloud Endpoints模板时的Proguard配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆