Proguard的及XStream与omitField()在Android [英] Proguard and XStream with omitField() on Android

查看:1299
本文介绍了Proguard的及XStream与omitField()在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用XStream的XML的,在我的Andr​​oid应用程序序列化,现在我在努力Proguard的(混淆器)加进来。

I was using XStream for deserialization of xml in my Android app, and now I'm struggling to add Proguard (obfuscator) to the mix.

下面是运行时例外,我遇到了(全:引擎收录):

Here's the runtime exception I run into (full: 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字段的任何类:

Needless to say this works fine without Proguard. I'm using shrinking, optimizing and obfuscating here, though I disabled it all on any XStream class, as well as any class that stands model for the xml fields:

-keep class net.lp.collectionista.jaxb.** { *; }
-keep class com.thoughtworks.xstream.** { *; }

我可以证实,从混淆罐,以及从mapping.txt(对于方法),所提到的任何类的存在和不混乱,所以原封不动AFAICT。我也是固定的注解。

I can confirm, from the obfuscated jar, as well as from the mapping.txt (for methods), that any classes mentioned exist and are not obfuscated, so untouched AFAICT. I also am retaining annotations.

唯一的例外是pretty的我清楚。我有:

The exception is pretty clear to me. I have:

        xstream.omitField(Feed.class, "id");

等等。看来omitField()调用不工作了,它开始因为Proguard的找一个id模型类。这是我在哪里卡住了,甚至潜入XStream的code之后。在模糊化的最终结果,整个omitField调用似乎是完整的,那么是什么在这里可能是另外坏了?它也应该不会是Feed.class作为一个也仍然存在。我在想什么?什么是调试一个很好的下一步是什么?

among others. It seems the omitField() call does not work anymore and it starts looking for an "id" model class, because of Proguard. This is where I am stuck, even after diving into the XStream code. The whole omitField call in the obfuscated end result seems to be intact, so what could be additionally broken here? It should also not be "Feed.class" as that one is also still there. What am I missing? What is a good next step for debugging?

编辑:我也注意到在我的混淆瓶子XStream的类的类文件比原有的略小,即使-dontoptimize。什么仍然被丢弃?

I did notice the class files of xstream classes in my obfuscated jar are slightly smaller than the original ones, even with -dontoptimize. What is still being dropped?

EDIT2:我开始认为这是与缺乏DEX警告类似以下内容:

I'm starting to think it has to do with the absence of dex warnings similar to the following:

[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.

...或许不是......

... or maybe not ...

EDIT3:最后,尽管涉及很多其他错误和问题,如<一的href="http://stackoverflow.com/questions/5701126/compile-with-proguard-gives-unexpected-top-level-exception">the SimException错误,我已经能够得到它在某些有限的情况下工作。这样,我可以查到它的模糊处理的步骤。也就是说,至少,如果我添加-dontobfuscate,问题消失。这不是我第一次玩的,所以它必须是解决方法的其他问题,或者更窄的配置,这解决了这个问题,以及。因此,这里是我再次问:当我使用-keep已经保障的XStream的主要部分,并从模糊我的模型类,那么还有什么可以创建这个烂摊子

Finally, in spite of dealing with many other bugs and problems such as the SimException bug, I've been able to get it working in some limited cases. That way I could pinpoint it to the obfuscation step. That is, at least, if I add "-dontobfuscate", the problem goes away. it isn't the first time I'm playing with that, so it must be the workarounds for the other problems, or the narrower configuration, that alleviates this problem as well. So here's me asking again: When I've already safeguarded the main parts of xstream and my model classes from obfuscation using "-keep", then what else could be creating this mess?

如果您需要更多的信息,让我知道。

If you need more info, let me know.

推荐答案

正如我所说的,这个问题就会消失,如果你 -dontobfuscate 但是让我们假设你不希望

As I said, the problem disappears if you -dontobfuscate but let's suppose you don't want that.

解决的办法是让更多的属性:

The solution is to keep more attributes:

-keepattributes EnclosingMethod, InnerClasses
-keepattributes *Annotation*
-keepattributes Signature

一旦你得到它的工作,你可以缩小它的XStream的code部位保持为好。我有:

Once you get it working you can narrow down which parts of the XStream code to keep as well. I have:

-keep class com.thoughtworks.xstream.converters.extended.SubjectConverter { *; }
-keep class com.thoughtworks.xstream.converters.extended.ThrowableConverter { *; }
-keep class com.thoughtworks.xstream.converters.extended.StackTraceElementConverter { *; }
-keep class com.thoughtworks.xstream.converters.extended.CurrencyConverter { *; }
-keep class com.thoughtworks.xstream.converters.extended.RegexPatternConverter { *; }
-keep class com.thoughtworks.xstream.converters.extended.CharsetConverter { *; }

-keep class com.thoughtworks.xstream.annotations.** { *; }

您还可以禁用很多相关的XStream警告。

You can also disable a lot of warnings related to XStream.

有关详细信息,你可以找到我的版本控制的项目文件的位置:

For more details you can find my version controlled project files here:

的build.xml

这篇关于Proguard的及XStream与omitField()在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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