Man*_*vis 6 google-app-engine android proguard google-cloud-endpoints android-studio
我们需要存储和检索用户在线使用我们的应用生成的内容.为此,我们决定使用Android Studio的集成Google Cloud Endpoints模板快速创建API(此处为官方用法示例).
它在调试中工作正常,但在发布模式下,启用Proguard后,它会失败.更糟糕的是,我没有找到任何关于在Android Studio的Endpoints模板中使用Proguard的文档或示例.
经过一个小时左右的探索并尝试使其工作,proguard-rules.pro现在看起来像这样:
-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.** { *; }
Run Code Online (Sandbox Code Playgroud)
使用此配置,我在我的类中获得了一个类强制转换异常ArrayAdapter:
java.lang.ClassCastException: com.google.api.client.util.ArrayMap cannot be cast to com.companyname.appname.application.backend.messageApi.model.Message
Run Code Online (Sandbox Code Playgroud)
这似乎不是什么地方执行返回的数据转换和,而不是一个List的Message对象,我得到List的com.google.api.client.util.ArrayMap对象(它们确实包含有效数据,顺便说一句).
我可以检查应用程序是否在发布模式下运行并手动进行转换,但是,这是一种hacky方式,我宁愿正确地执行此操作.那么,有人可以告诉我Proguard配置文件中缺少什么吗?
mya*_*mal 18
我在其中一个应用程序中使用端点执行类似的操作.我也有一些Proguard的问题(不记得究竟是什么).
我的Proguard规则的这一部分似乎适用:
# 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
Run Code Online (Sandbox Code Playgroud)
我不知道是否有必要,但我也有这个部分:
# 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 *;
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
1064 次 |
| 最近记录: |