Proguard keep class names?

爷,独闯天下 提交于 2019-12-17 23:27:08

问题


Hello I am writing an Android app and I have set up Proguard to obfuscate my application. I however use a classloader to dynamically load different extensions to my application. The problem is that these don't load correctly if their names are changed. How do I keep Proguard from obfuscating specific class names?


回答1:


Use the -keepnames option in your proguard.cfg

Refer to the manual https://www.guardsquare.com/en/proguard/manual/usage#keepoptions:

-keepnames class_specification

Short for -keep,allowshrinking class_specification

Specifies classes and class members whose names are to be preserved, if they aren't removed in the shrinking phase. For example, you may want to keep all class names of classes that implement the Serializable interface, so that the processed code remains compatible with any originally serialized classes. Classes that aren't used at all can still be removed. Only applicable when obfuscating.




回答2:


This keeps classnames intact:

-keepnames class com.somepackage.* 



回答3:


Handy tip for everyone who does not want ProGuard to change any class name:

# please KEEP ALL THE NAMES
-keepnames class ** { *; }

This way you will get readable stack traces while still throwing out things you don't need. :-)




回答4:


If anyone is interested how to specify multiple class names to keep, then these classes can be separated by a comma. Example:

-keepnames class com.foo.**,com.bar.** { *; }

It is also possible to use negation with this because usually own classes whould be obfuscated so 3rd party libraries can be kept:

-keepnames class !com.foo.**,!com.bar.** { *; }

See the Proguard Documentation for this.



来源:https://stackoverflow.com/questions/10971810/proguard-keep-class-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!