【发布时间】:2011-09-19 02:02:13
【问题描述】:
我在我的 Android 应用程序中使用 XStream 对 xml 进行反序列化,现在我正在努力将 Proguard(混淆器)添加到组合中。
这是我遇到的运行时异常(完整:pastebin):
WARN/System.err(6209): net.lp.collectionista.util.a.g: XStream could not parse the response
WARN/System.err(6209): at net.lp.collectionista.a.s.a(Collectionista:215)
...
WARN/System.err(6209): Caused by: com.thoughtworks.xstream.converters.ConversionException: id : id in loader dalvik.system.PathClassLoader[/data/app/net.lp.collectionista-2.apk] : id : id in loader dalvik.system.PathClassLoader[/data/app/net.lp.collectionista-2.apk]
WARN/System.err(6209): ---- Debugging information ----
WARN/System.err(6209): message : id : id in loader dalvik.system.PathClassLoader[/data/app/net.lp.collectionista-2.apk]
WARN/System.err(6209): cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
WARN/System.err(6209): cause-message : id : id in loader dalvik.system.PathClassLoader[/data/app/net.lp.collectionista-2.apk]
WARN/System.err(6209): class : net.lp.collectionista.jaxb.googlebooks.search.Feed
WARN/System.err(6209): required-type : java.lang.Object
WARN/System.err(6209): path : /feed/entry/id
WARN/System.err(6209): line number : 1
WARN/System.err(6209): -------------------------------
WARN/System.err(6209): at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(Collectionista:89)
...
WARN/System.err(6209): at com.thoughtworks.xstream.XStream.fromXML(Collectionista:861)
...
WARN/System.err(6209): Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: id : id in loader dalvik.system.PathClassLoader[/data/app/net.lp.collectionista-2.apk]
WARN/System.err(6209): at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(Collectionista:68)
...
不用说,没有 Proguard 也能正常工作。我在这里使用了缩小、优化和混淆,尽管我在任何 XStream 类以及任何代表 xml 字段模型的类上都禁用了它:
-keep class net.lp.collectionista.jaxb.** { *; }
-keep class com.thoughtworks.xstream.** { *; }
我可以从混淆的 jar 以及 mapping.txt(用于方法)中确认,提到的任何类都存在并且没有被混淆,因此未触及 AFAICT。我也保留注释。
我很清楚这个例外。我有:
xstream.omitField(Feed.class, "id");
等等。由于 Proguard,omitField() 调用似乎不再起作用,它开始寻找“id”模型类。这就是我被卡住的地方,即使在深入研究 XStream 代码之后也是如此。混淆的最终结果中的整个 omitField 调用似乎是完整的,那么这里还有什么可以破坏的呢?它也不应该是“Feed.class”,因为那个也仍然存在。我错过了什么?调试的下一步是什么?
编辑:我确实注意到我的混淆 jar 中的 xstream 类的类文件比原始的略小,即使使用 -dontoptimize。什么还在被丢弃?
EDIT2:我开始认为这与缺少类似于以下的 dex 警告有关:
[apply] warning: Ignoring InnerClasses attribute for an anonymous inner class
[apply] (com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$1) that doesn't come with an
[apply] associated EnclosingMethod attribute. This class was probably produced by a
[apply] compiler that did not target the modern .class file format. The recommended
[apply] solution is to recompile the class from source, using an up-to-date compiler
[apply] and without specifying any "-target" type options. The consequence of ignoring
[apply] this warning is that reflective operations on this class will incorrectly
[apply] indicate that it is *not* an inner class.
...也许不是...
EDIT3: 最后,尽管处理了许多其他错误和问题,例如the SimException bug,但我仍然能够在一些有限的情况下使其正常工作。这样我就可以将其精确定位到混淆步骤。也就是说,至少,如果我添加“-dontobfuscate”,问题就会消失。这不是我第一次玩这个,所以它必须是其他问题的解决方法,或者更窄的配置,也可以缓解这个问题。所以我再次问:当我已经使用“-keep”保护了 xstream 的主要部分和我的模型类免受混淆时,还有什么可能造成这种混乱?
如果您需要更多信息,请告诉我。
【问题讨论】:
标签: android obfuscation deserialization xstream proguard