Trimming Unused Code - RetroGuard Documentation


Prev   Contents   Next

[RetroGuard-v2.1.x and later]

RetroGuard can remove unused classes during obfuscation. When including a Java library in your obfuscated jar, large parts of the library may be unused by your particular application. These unused methods, fields, and even whole classes add unnecessary bulk to your deployed software. To have RetroGuard trim this unused code during obfuscation, add a script line:

.option Trim

Since this trimming occurs at the Java class level some of the results, while correct, may be unexpected. In particular, references to static final fields (constants) are usually optimized away during compilation. These fields will therefore be removed even though they seem to be referenced in the Java source. This has no adverse effect at the Java class-file level.

Trim and Patch Files

Use of .option Trim is not recommended when generation of patch files is planned. See Creating patch files for more details on patch file generation. This is because of the difficulty in working out which classes would need to be included in the patch jars. With trimming enabled this would be a mixture of updated classes, along with classes which were partially or fully trimmed in the original version but which are now referenced in updated code.

Trim and Reflection

RetroGuard's .option Trim has no awareness of reflection methods, and will therefore remove code which is only referenced by reflection. The solution is to preserve class, method, or field identifiers which are referenced by reflection, by including them in the RetroGuard script file.


Prev   Contents   Next
 Copyright © 1998-2007 Retrologic Systems.
 All rights reserved.