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?
Use the -keepnames
option in your proguard.cfg
Refer to the manual https://www.guardsquare.com/manual/configuration/usage#keepoptions
-keepnames
class_specificationShort for
-keep,allowshrinking
class_specificationSpecifies 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.
-keep
and -keepnames
do the same as far as obfuscation is concerned (class names specified in class_specification
are kept). As stated above, the difference is in the shrinking phase (with -keepnames
, an unused class name is removed instead of kept). Both of them will however obfuscate class members, except if you add a specification to prevent this: adding e.g. {*;}
at the end of class_specification
(to keep all class members). Note that adding {}
is the same as adding no curly brackets at all. –
Pammy This keeps classnames intact:
-keepnames class com.somepackage.*
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. :-)
-dontobfuscate
is the right way to disable obfuscation. –
Suckle 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 only own classes would be obfuscated and 3rd party libraries can be kept:
-keepnames class !com.foo.**,!com.bar.** { *; }
See the Proguard Documentation for this.
© 2022 - 2024 — McMap. All rights reserved.