如果android应用中使用了反射功能,比如JSON的序列化和反序列化,要求某些实体类的字段和方法保持不变,设置方法为
-keep public class * implements android.os.Parcelable{
public protected private *;} 这里 public protected private *就是匹配该类的任一方法和字段。
下边是摘录的ProGuard常用匹配选项,参考:http://proguard.sourceforge.net/index.html#manual/usage.html。
- The
class
keyword refers to any interface or class. Theinterface
keyword restricts matches to interface classes. Theenum
keyword restricts matches to enumeration classes. Preceding theinterface
orenum
keywords by a!
restricts matches to classes that are not interfaces or enumerations, respectively. - Every classname must be fully qualified, e.g.
java.lang.String
. Class names may be specified as regular expressions containing the following wildcards: -
?
matches any single character in a class name, but not the package separator. For example, " mypackage.Test?
" matches "mypackage.Test1
" and "mypackage.Test2
", but not "mypackage.Test12
".*
matches any part of a class name not containing the package separator. For example, " mypackage.*Test*
" matches "mypackage.Test
" and "mypackage.YourTestApplication
", but not "mypackage.mysubpackage.MyTest
". Or, more generally, "mypackage.*
" matches all classes in "mypackage
", but not in its subpackages.**
matches any part of a class name, possibly containing any number of package separators. For example, " **.Test
" matches allTest
classes in all packages except the root package. Or, "mypackage.**
" matches all classes in "mypackage
" and in its subpackages. - For additional flexibility, class names can actually be comma-separated lists of class names, with optional
!
negators, just like file name filters. This notation doesn't look very Java-like, so it should be used with moderation. - The
extends
andimplements
specifications are typically used to restrict classes with wildcards. They are currently equivalent, specifying that only classes extending or implementing the given class qualify. Note that the given class itself is not included in this set. If required, it should be specified in a separate option. - The
@
specifications can be used to restrict classes and class members to the ones that are annotated with the specified annotation types. An annotationtype is specified just like a classname. - Fields and methods are specified much like in Java, except that method argument lists don't contain argument names (just like in other tools like
javadoc
andjavap
). The specifications can also contain the following catch-all wildcards: -
<init>
matches any constructor. <fields>
matches any field. <methods>
matches any method. *
matches any field or method. - Note that the above wildcards don't have return types. Only the
<init>
wildcard has an argument list.
Types in descriptors can contain the following wildcards:?
matches any single character in a method name. *
matches any part of a method name. -
For convenience and for backward compatibility, the class name
*
refers to any class, irrespective of its package. -
Fields and methods may also be specified using regular expressions. Names can contain the following wildcards:
%
matches any primitive type (" boolean
", "int
", etc, but not "void
").?
matches any single character in a class name. *
matches any part of a class name not containing the package separator. **
matches any part of a class name, possibly containing any number of package separators. ***
matches any type (primitive or non-primitive, array or non-array). ...
matches any number of arguments of any type.