Search This Blog

2013-05-15

Proguard使用经验

以前维护过一个Android项目,Proguard配置得过于简陋,拿不到好用的堆栈,所以我就看了下。
使用的是4.7版本。

1 Android

http://proguard.sourceforge.net/manual/examples.html#androidapplication
Android SDK自带的Proguard版本太旧,可以在http://proguard.sourceforge.net/downloads.html下载最新版,examples/android.pro是给android用的,内容挺好,基本上可以直接用。
我本来是直接去找每一个需要的选项,这是后来发现的。

2 Proguard的一个问题

mapping.txt里有错,一部分自己的类消失了,方法都跑到库所在的类里,导致retrace得不到完整的堆栈。这个问题不好找,只能靠猜,后来发现是优化搞的鬼,设置-dontoptimize禁用优化就好了。

3 某些有用的选项

3.1 keepattributes

-keepattributes SourceFile,LineNumberTable
保留源码文件、行号

3.2 useuniqueclassmembernames

-useuniqueclassmembernames
Without the option, more class members can be mapped to the same short names like 'a', 'b', etc.

3.3 applymapping

-applymapping filename
Specifies to reuse the given name mapping that was printed out in a previous obfuscation run of ProGuard. Classes and class members that are listed in the mapping file receive the names specified along with them. Classes and class members that are not mentioned receive new names. The mapping may refer to input classes as well as library classes. This option can be useful for incremental obfuscation, i.e. processing add-ons or small patches to an existing piece of code. In such cases, you should consider whether you also need the option -useuniqueclassmembernames. Only a single mapping file is allowed. Only applicable when obfuscating.

3.4 dontobfuscate

-dontobfuscate
Specifies not to obfuscate the input class files. By default, obfuscation is applied; classes and class members receive new short random names, except for the ones listed by the various -keep options. Internal attributes that are useful for debugging, such as source files names, variable names, and line numbers are removed.

3.5 Class Specifications

http://proguard.sourceforge.net/manual/usage.html#classspecification
** matches any part of a class name, possibly containing any number of package separators. For example, "**.Test" matches all Test classes in all packages except the root package. Or, "mypackage.**" matches all classes in "mypackage" and in its subpackages.

4 参考资料

http://proguard.sourceforge.net/manual/usage.html
http://proguard.sourceforge.net/manual/examples.html

=文章版本=

201201
20130515

No comments:

Post a Comment