Android的ProGuard的,和keepclasseswithmembernames [英] Android, ProGuard, and keepclasseswithmembernames
问题描述
在的ProGuard的configs一个常见的模式Android应用程序是preserve定制查看
类,因为它们可能只从布局XML,而不是应用程序$ C $引用℃。
A common pattern in ProGuard configs for Android applications is to preserve custom View
classes, since they are probably referenced only from layout XML instead of application code.
在项目创建,在ADT因此添加这些规则,以一个项目的proguard.cfg:
Upon project creation, the ADT therefore add these rules to a project's proguard.cfg:
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
我想这里的想法是说,当一个类定义一个构造函数,可以通过布局充气调用,那么preserve它。然而,根据ProGuard的文档中, keepclasseswithmembernames
预选赛是速记 keepclasseswithmembers
和 allowshrinking
,而如果我理解正确的话的意思是:它允许删除这些类,但如果他们保持,不要混淆它的成员的名字(可能不会打破绑定的XML属性名和类的setter)。
I guess the idea here is to say that whenever a class defines a constructor that may be called by a layout inflater, then preserve it. However, according to the ProGuard docs, the keepclasseswithmembernames
qualifier is shorthand for keepclasseswithmembers
and allowshrinking
, which if I understand correctly means: it's allowed to remove these classes, but if they're kept, don't obfuscate its member names (probably to not break bindings between XML attribute names and class setters).
但并不意味着这些类仍然会在收缩阶段删除(allowshrinking = TRUE),除非他们是在code直接引用?事实上,这是发生了什么事,我们正在使用我们的应用程序,自定义窗口小部件,我可以通过设置规则解决问题,只是 keepclasseswithmembers
因为这将只需$ P $完全pserve匹配类(这是值得注意的是,这是href="http://proguard.sourceforge.net/manual/examples.html#androidapplication"> ProGuard的安卓例如确实官方
But doesn't that mean that those classes will still be removed during the shrinking phase (allowshrinking = true), unless they are referenced directly in code? Indeed that is what happened with a custom widget we're using in our app, and I could fix the issue by setting the rule to just keepclasseswithmembers
since that will simply preserve the matching classes entirely (it's worth noting that this is what the official ProGuard Android example does, too).
我是不是误读ProGuard的文档或这是在ADT项目向导中的错误?
Am I misreading the ProGuard docs or is this a bug in the ADT project wizard?
推荐答案
在Android SDK(至少高达11版)的配置是不完全正确的,确实如此。
The configuration in the Android SDK (at least up to version 11) is not entirely correct, indeed.
对于Android ProGuard文档中的配置正确指定-keepclasseswithmembers,而不是-keepclasseswithmembernames
The configuration for Android in the ProGuard documentation correctly specifies "-keepclasseswithmembers", not "-keepclasseswithmembernames".
这篇关于Android的ProGuard的,和keepclasseswithmembernames的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!