Troubleshooting
There are a couple of things you should be aware of when obfuscating and shrinking software. The weakest part of an application considering name obfuscation and code shrinking is code that uses reflection to dynamically load classes, invoke methods etc. Therefore, you have to be especially careful when using the yguard task on applications that rely on reflection. The most important facts to keep in mind when using yGuard are described here briefly:
- If you use the
renametask, code in the form ofMyApplication.classwill break ifMyApplicationwill be obfuscated by name and the obfuscation switch replaceClassNameStrings is set tofalse. Theshrinktask will currently recognize code in the form ofMyApplication.classonly if the java files were compiled using an arbitrary version of the standard javac compiler (although the shrinking engine might recognize the.classconstruct also if the classes were compiled using a compiler that generates similar bytecode). - Automatic introspection and reflection will break in most cases, when you decide to obfuscate the corresponding methods and fields. If you use the
shrinktask and your application uses reflection you should explicitly designate all entities loaded per reflection as code entrypoints using the keep element. If your application is broken after using theshrinktask, consider using the createStubs attribute of theshrinktask to find out which additional entities you need to include in the keep element. Class.forName(className)will not work when using therenametask unless you use the obfuscated name string in your variable or the String is a local constant and replaceClassNameStrings is not set or set totrue. If you use theshrinktask,classNameshould be contained in the list of entrypoints using thekeepelement.- The customized serialization mechanism will not work if you obfuscated or shrinked the writeObject and readObject methods as well as the serializationUID field.
- Simple bean introspection will not work, if you decide to obfuscate your public accessor methods, since it makes use of reflection.
- If you do not set the
-Xmxproperty for the Java virtual machine, theyguardAnt task might fail due to ajava.lang.OutOfMemoryError. To solve this problem, set the-Xmxoption in theANT_OPTSvariable, e.g.:
bash> export ANT_OPTS="-Xmx512M"
or
cshell> setenv ANT_OPTS "-Xmx512M"