Proguard和XStream注释的问题

时间:2014-09-10 03:09:01

标签: android obfuscation proguard xstream

到目前为止,我一直在这里处理各种各样的问题,到目前为止还没有运气。在编写我的应用程序之后,当我尝试通过XStream运行POJO类时,会发生以下崩溃:

09-09 23:01:51.188: E/AndroidRuntime(18692): java.lang.annotation.IncompleteAnnotationException: The element value is not complete for the annotation com.thoughtworks.xstream.annotations.XStreamConverter
09-09 23:01:51.188: E/AndroidRuntime(18692):    at libcore.reflect.AnnotationFactory.invoke(AnnotationFactory.java:301)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at java.lang.reflect.Proxy.invoke(Proxy.java:379)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at $Proxy2.value(Unknown Source)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at com.thoughtworks.xstream.mapper.AnnotationMapper.cacheConverter(SourceFile:515)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at com.thoughtworks.xstream.mapper.AnnotationMapper.processLocalConverterAnnotation(SourceFile:472)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at com.thoughtworks.xstream.mapper.AnnotationMapper.processTypes(SourceFile:222)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at com.thoughtworks.xstream.mapper.AnnotationMapper.processAnnotations(SourceFile:164)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at com.thoughtworks.xstream.XStream.processAnnotations(SourceFile:1971)
09-09 23:01:51.188: E/AndroidRuntime(18692):    at com.thoughtworks.xstream.XStream.processAnnotations(SourceFile:1982)

在查看了各种其他SO帖子以及Proguard文档之后,我在我的proguard配置文件中有以下内容:

-keepattributes SourceFile, LineNumberTable, *Annotation*, Signature, EnclosingMethod, InnerClasses
-dontwarn com.thoughtworks.**

# For serializable classes
-keepnames class * extends java.io.Serializable

# For serializable classes
-keepclassmembers class * extends java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

# Keep everything in the XStream Package
-keep class com.thoughtworks.** {
    *;
}
# Keep my XStreamExporter class
-keep class com.mypackage_name.data.exporters.XStreamExporter {
    *;
}

序列化保持我的POJO类完整,如seeds.txt输出所确认。我已经尝试过关于这个问题的所有想法/发现。我错过了什么?

1 个答案:

答案 0 :(得分:1)

如果您使用Android SDK中包含的Proguard,您可能正在使用旧版本(4.5?我认为)。

版本4.9之前的Proguard可能会出现删除注释的问题。

  

修正过度激进的类注释收缩。 - http://proguard.sourceforge.net/downloads.html,版本4.9的更改列表中的第6个项目符号。

使用最新版本5.0(http://sourceforge.net/projects/proguard/files/proguard/)替换SDK中的jar,尝试最新版本的Proguard。要替换的jar位于android-sdk / tools / proguard / lib / proguard.jar。