Home | History | Annotate | Download | only in manual
      1 <!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      2 <html>
      3 <head>
      4 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
      5 <meta http-equiv="content-style-type" content="text/css">
      6 <link rel="stylesheet" type="text/css" href="style.css">
      7 <title>ProGuard Usage</title>
      8 <script type="text/javascript" language="JavaScript">
      9 <!--
     10 if (window.self==window.top)
     11   window.top.location.replace("../index.html#"+window.location.pathname+window.location.hash);
     12 else {
     13   var hash="#"+window.location.pathname.replace(window.top.location.pathname.replace("index.html", ""), "");
     14   if (window.top.location.hash!=hash)
     15     window.top.location.hash=hash;
     16 }
     17 //-->
     18 </script>
     19 </head>
     20 <body>
     21 
     22 <h2>Usage</h2>
     23 
     24 To run ProGuard, just type:
     25 <p class="code">
     26 <code><b>java -jar proguard.jar </b></code><i>options</i> ...
     27 </p>
     28 You can find the ProGuard jar in the <code>lib</code> directory of the
     29 ProGuard distribution. Alternatively, the <code>bin</code> directory contains
     30 some short Linux and Windows scripts containing this command. Typically, you'll
     31 put most options in a configuration file (say, <code>myconfig.pro</code>), and
     32 just call:
     33 <p class="code">
     34 <code><b>java -jar proguard.jar @myconfig.pro</b></code>
     35 </p>
     36 You can combine command line options and options from configuration files. For
     37 instance:
     38 <p class="code">
     39 <code><b>java -jar proguard.jar @myconfig.pro -verbose</b></code>
     40 </p>
     41 <p>
     42 You can add comments in a configuration file, starting with a
     43 <code><b>#</b></code> character and continuing until the end of the line.
     44 <p>
     45 Extra whitespace between words and delimiters is ignored. File names with
     46 spaces or special characters should be quoted with single or double quotes.
     47 <p>
     48 Options can be grouped arbitrarily in arguments on the command line and in
     49 lines in configuration files. This means that you can quote arbitrary sections
     50 of command line options, to avoid shell expansion of special characters, for
     51 instance.
     52 <p>
     53 The order of the options is generally irrelevant. For quick experiments, you
     54 can abbreviate them to their first unique characters.
     55 <p>
     56 
     57 The sections below provide more details:
     58 <ul>
     59 <li><a href="#iooptions">Input/Output Options</a></li>
     60 <li><a href="#keepoptions">Keep Options</a></li>
     61 <li><a href="#shrinkingoptions">Shrinking Options</a></li>
     62 <li><a href="#optimizationoptions">Optimization Options</a></li>
     63 <li><a href="#obfuscationoptions">Obfuscation Options</a></li>
     64 <li><a href="#preverificationoptions">Preverification Options</a></li>
     65 <li><a href="#generaloptions">General Options</a></li>
     66 <li><a href="#classpath">Class Paths</a></li>
     67 <li><a href="#filename">File Names</a></li>
     68 <li><a href="#filefilters">File Filters</a></li>
     69 <li><a href="#filters">Filters</a></li>
     70 <li><a href="#keepoverview">Overview of <code>Keep</code> Options</a></li>
     71 <li><a href="#keepoptionmodifiers">Keep Option Modifiers</a></li>
     72 <li><a href="#classspecification">Class Specifications</a></li>
     73 </ul>
     74 
     75 <h2><a name="iooptions">Input/Output Options</a></h2>
     76 
     77 <dl>
     78 <dt><a name="at"><code><b>@</b></code></a><a href="#filename"><i>filename</i></a></dt>
     79 
     80 <dd>Short for '<a href="#include"><code>-include</code></a>
     81      <a href="#filename"><i>filename</i></a>'.</dd>
     82 
     83 <dt><a name="include"><code><b>-include</b></code></a>
     84     <a href="#filename"><i>filename</i></a></dt>
     85 
     86 <dd>Recursively reads configuration options from the given file
     87     <i>filename</i>.</dd>
     88 
     89 <dt><a name="basedirectory"><code><b>-basedirectory</b></code></a>
     90     <a href="#filename"><i>directoryname</i></a></dt>
     91 
     92 <dd>Specifies the base directory for all subsequent relative file names in
     93     these configuration arguments or this configuration file.</dd>
     94 
     95 <dt><a name="injars"><code><b>-injars</b></code></a>
     96     <a href="#classpath"><i>class_path</i></a></dt>
     97 
     98 <dd>Specifies the input jars (or wars, ears, zips, or directories) of the
     99     application to be processed. The class files in these jars will be
    100     processed and written to the output jars. By default, any non-class files
    101     will be copied without changes. Please be aware of any temporary files
    102     (e.g. created by IDEs), especially if you are reading your input files
    103     straight from directories. The entries in the class path can be filtered,
    104     as explained in the <a href="#filefilters">filters</a> section. For better
    105     readability, class path entries can be specified using multiple
    106     <code>-injars</code> options.</dd>
    107 
    108 <dt><a name="outjars"><code><b>-outjars</b></code></a>
    109     <a href="#classpath"><i>class_path</i></a></dt>
    110 
    111 <dd>Specifies the names of the output jars (or wars, ears, zips, or
    112     directories). The processed input of the preceding <code>-injars</code>
    113     options will be written to the named jars. This allows you to collect the
    114     contents of groups of input jars into corresponding groups of output jars.
    115     In addition, the output entries can be filtered, as explained in
    116     the <a href="#filefilters">filters</a> section. Each processed class file
    117     or resource file is then written to the first output entry with a matching
    118     filter, within the group of output jars.
    119     <p>
    120     You must avoid letting the output files overwrite any input files. For
    121     better readability, class path entries can be specified using multiple
    122     <code>-outjars</code> options. Without any <code>-outjars</code> options,
    123     no jars will be written.</dd>
    124 
    125 <dt><a name="libraryjars"><code><b>-libraryjars</b></code></a>
    126     <a href="#classpath"><i>class_path</i></a></dt>
    127 
    128 <dd>Specifies the library jars (or wars, ears, zips, or directories) of the
    129     application to be processed. The files in these jars will not be included
    130     in the output jars. The specified library jars should at least contain the
    131     class files that are <i>extended</i> by application class files. Library
    132     class files that are only <i>called</i> needn't be present, although their
    133     presence can improve the results of the optimization step. The entries in
    134     the class path can be filtered, as explained in the <a
    135     href="#filefilters">filters</a> section. For better readability, class path
    136     entries can be specified using multiple <code>-libraryjars</code> options.
    137     <p>
    138     Please note that the boot path and the class path set for running ProGuard
    139     are not considered when looking for library classes. This means that you
    140     explicitly have to specify the run-time jar that your code will use.
    141     Although this may seem cumbersome, it allows you to process applications
    142     targeted at different run-time environments. For example, you can process
    143     <a href="examples.html#application">J2SE applications</a> as well as <a
    144     href="examples.html#midlet">JME midlets</a>, just by specifying the
    145     appropriate run-time jar.</dd>
    146 
    147 <dt><a name="skipnonpubliclibraryclasses"><code><b>-skipnonpubliclibraryclasses</b></code></a></dt>
    148 
    149 <dd>Specifies to skip non-public classes while reading library jars, to speed
    150     up processing and reduce memory usage of ProGuard. By default, ProGuard
    151     reads non-public and public library classes alike. However, non-public
    152     classes are often not relevant, if they don't affect the actual program
    153     code in the input jars. Ignoring them then speeds up ProGuard, without
    154     affecting the output. Unfortunately, some libraries, including recent JSE
    155     run-time libraries, contain non-public library classes that are extended
    156     by public library classes. You then can't use this option. ProGuard will
    157     print out warnings if it can't find classes due to this option being
    158     set.</dd>
    159 
    160 <dt><a name="dontskipnonpubliclibraryclasses"><code><b>-dontskipnonpubliclibraryclasses</b></code></a></dt>
    161 
    162 <dd>Specifies not to ignore non-public library classes. As of version 4.5, this
    163     is the default setting.</dd>
    164 
    165 <dt><a name="dontskipnonpubliclibraryclassmembers"><code><b>-dontskipnonpubliclibraryclassmembers</b></code></a></dt>
    166 
    167 <dd>Specifies not to ignore package visible library class members (fields and
    168     methods). By default, ProGuard skips these class members while parsing
    169     library classes, as program classes will generally not refer to them.
    170     Sometimes however, program classes reside in the same packages as library
    171     classes, and they do refer to their package visible class members. In
    172     those cases, it can be useful to actually read the class members, in order
    173     to make sure the processed code remains consistent.</dd>
    174 
    175 <dt><a name="keepdirectories"><code><b>-keepdirectories</b></code></a>
    176     [<i><a href="#filefilters">directory_filter</a></i>]</dt>
    177 
    178 <dd>Specifies the directories to be kept in the output jars (or wars, ears, or
    179     directories). By default, directory entries are removed. This reduces the
    180     jar size, but it may be undesirable if the program code tries to find them
    181     with constructs like "<code>MyClass.class.getResource("")</code>". If the
    182     option is specified without a filter, all directories are kept. With a
    183     filter, only matching directories are kept.</dd>
    184 
    185 <dt><a name="target"><code><b>-target</b></code></a> <i>version</i></dt>
    186 
    187 <dd>Specifies the version number to be set in the processed class files. The
    188     version number can be one of <code>1.0</code>, <code>1.1</code>,
    189     <code>1.2</code>, <code>1.3</code>, <code>1.4</code>, <code>1.5</code> (or
    190     just <code>5</code>), <code>1.6</code> (or just <code>6</code>), or
    191      <code>1.7</code> (or just <code>7</code>). By default, the version numbers
    192     of the class files are left unchanged. For example, you may want to
    193     <a href="examples.html#upgrade">upgrade class files to Java 6</a>, by
    194     changing their version numbers and having them preverified.</dd>
    195 
    196 <dt><a name="forceprocessing"><code><b>-forceprocessing</b></code></a></dt>
    197 
    198 <dd>Specifies to process the input, even if the output seems up to date. The
    199     up-to-dateness test is based on a comparison of the date stamps of the
    200     specified input, output, and configuration files or directories.</dd>
    201 
    202 </dl>
    203 <p>
    204 
    205 <h2><a name="keepoptions">Keep Options</a></h2>
    206 
    207 <dl>
    208 <dt><a name="keep"><code><b>-keep</b></code></a>
    209     [<a href="#keepoptionmodifiers">,<i>modifier</i></a>,...]
    210     <a href="#classspecification"><i>class_specification</i></a></dt>
    211 
    212 <dd>Specifies classes and class members (fields and methods) to be preserved
    213     as entry points to your code. For example, in order to <a
    214     href="examples.html#application">keep an application</a>, you can specify
    215     the main class along with its main method. In order to <a
    216     href="examples.html#library">process a library</a>, you should specify all
    217     publicly accessible elements.</dd>
    218 
    219 <dt><a name="keepclassmembers"><code><b>-keepclassmembers</b></code></a>
    220     [<a href="#keepoptionmodifiers">,<i>modifier</i></a>,...]
    221     <a href="#classspecification"><i>class_specification</i></a></dt>
    222 
    223 <dd>Specifies class members to be preserved, if their classes are preserved as
    224     well. For example, you may want to <a
    225     href="examples.html#serializable">keep all serialization fields and
    226     methods</a> of classes that implement the <code>Serializable</code>
    227     interface.</dd>
    228 
    229 <dt><a name="keepclasseswithmembers"><code><b>-keepclasseswithmembers</b></code></a>
    230     [<a href="#keepoptionmodifiers">,<i>modifier</i></a>,...]
    231     <a href="#classspecification"><i>class_specification</i></a></dt>
    232 
    233 <dd>Specifies classes and class members to be preserved, on the condition that
    234     all of the specified class members are present. For example, you may want
    235     to <a href="examples.html#applications">keep all applications</a> that
    236     have a main method, without having to list them explicitly.</dd>
    237 
    238 <dt><a name="keepnames"><code><b>-keepnames</b></code></a>
    239     <a href="#classspecification"><i>class_specification</i></a></dt>
    240 
    241 <dd>Short for <a href="#keep"><code>-keep</code></a>,<a href="#allowshrinking"><code>allowshrinking</code></a>
    242     <a href="#classspecification"><i>class_specification</i></a>
    243     <p>
    244     Specifies classes and class members whose names are to be preserved, if
    245     they aren't removed in the shrinking phase. For example, you may want to
    246     <a href="examples.html#serializable">keep all class names</a> of classes
    247     that implement the <code>Serializable</code> interface, so that the
    248     processed code remains compatible with any originally serialized classes.
    249     Classes that aren't used at all can still be removed. Only applicable when
    250     obfuscating.</dd>
    251 
    252 <dt><a name="keepclassmembernames"><code><b>-keepclassmembernames</b></code></a>
    253     <a href="#classspecification"><i>class_specification</i></a></dt>
    254 
    255 <dd>Short for <a href="#keepclassmembers"><code>-keepclassmembers</code></a>,<a href="#allowshrinking"><code>allowshrinking</code></a>
    256     <a href="#classspecification"><i>class_specification</i></a>
    257     <p>
    258     Specifies class members whose names are to be preserved, if they aren't
    259     removed in the shrinking phase. For example, you may want to preserve the
    260     name of the synthetic <code>class$</code> methods
    261     when <a href="examples.html#library">processing a library</a> compiled by
    262     JDK 1.2 or older, so obfuscators can detect it again when processing an
    263     application that uses the processed library (although ProGuard itself
    264     doesn't need this). Only applicable when obfuscating.</dd>
    265 
    266 <dt><a name="keepclasseswithmembernames"><code><b>-keepclasseswithmembernames</b></code></a>
    267     <a href="#classspecification"><i>class_specification</i></a></dt>
    268 
    269 <dd>Short for <a href="#keepclasseswithmembers"><code>-keepclasseswithmembers</code></a>,<a href="#allowshrinking"><code>allowshrinking</code></a>
    270     <a href="#classspecification"><i>class_specification</i></a>
    271     <p>
    272     Specifies classes and class members whose names are to be preserved, on
    273     the condition that all of the specified class members are present after
    274     the shrinking phase. For example, you may want to <a
    275     href="examples.html#native">keep all native method names</a> and the names
    276     of their classes, so that the processed code can still link with the
    277     native library code. Native methods that aren't used at all can still be
    278     removed. If a class file is used, but none of its native methods are, its
    279     name will still be obfuscated. Only applicable when obfuscating.</dd>
    280 
    281 <dt><a name="printseeds"><code><b>-printseeds</b></code></a>
    282     [<a href="#filename"><i>filename</i></a>]</dt>
    283 
    284 <dd>Specifies to exhaustively list classes and class members matched by the
    285     various <code>-keep</code> options. The list is printed to the standard
    286     output or to the given file. The list can be useful to verify if the
    287     intended class members are really found, especially if you're using
    288     wildcards. For example, you may want to list all the <a
    289     href="examples.html#applications">applications</a> or all the <a
    290     href="examples.html#applets">applets</a> that you are keeping.</dd>
    291 
    292 </dl>
    293 <p>
    294 
    295 <h2><a name="shrinkingoptions">Shrinking Options</a></h2>
    296 
    297 <dl>
    298 <dt><a name="dontshrink"><code><b>-dontshrink</b></code></a></dt>
    299 
    300 <dd>Specifies not to shrink the input class files. By default, shrinking is
    301     applied; all classes and class members are removed, except for the ones
    302     listed by the various <code>-keep</code> options, and the ones on which
    303     they depend, directly or indirectly. A shrinking step is also applied
    304     after each optimization step, since some optimizations may open the
    305     possibility to remove more classes and class members.</dd>
    306 
    307 <dt><a name="printusage"><code><b>-printusage</b></code></a>
    308     [<a href="#filename"><i>filename</i></a>]</dt>
    309 
    310 <dd>Specifies to list dead code of the input class files. The list is printed
    311     to the standard output or to the given file. For example, you can <a
    312     href="examples.html#deadcode">list the unused code of an application</a>.
    313     Only applicable when shrinking.</dd>
    314 
    315 <dt><a name="whyareyoukeeping"><code><b>-whyareyoukeeping</b></code></a>
    316     <a href="#classspecification"><i>class_specification</i></a></dt>
    317 
    318 <dd>Specifies to print details on why the given classes and class members are
    319     being kept in the shrinking step. This can be useful if you are wondering
    320     why some given element is present in the output. In general, there can be
    321     many different reasons. This option prints the shortest chain of methods
    322     to a specified seed or entry point, for each specified class and class
    323     member. <i>In the current implementation, the shortest chain that is
    324     printed out may sometimes contain circular deductions -- these do not
    325     reflect the actual shrinking process.</i> If the <a
    326     href="#verbose"><code>-verbose</code></a> option if specified, the traces
    327     include full field and method signatures. Only applicable when
    328     shrinking.</dd>
    329 
    330 </dl>
    331 <p>
    332 
    333 <h2><a name="optimizationoptions">Optimization Options</a></h2>
    334 
    335 <dl>
    336 <dt><a name="dontoptimize"><code><b>-dontoptimize</b></code></a></dt>
    337 
    338 <dd>Specifies not to optimize the input class files. By default, optimization
    339     is enabled; all methods are optimized at a bytecode level.</dd>
    340 
    341 <dt><a name="optimizations"><code><b>-optimizations</b></code></a>
    342     <a href="optimizations.html"><i>optimization_filter</i></a></dt>
    343 
    344 <dd>Specifies the optimizations to be enabled and disabled, at a more
    345     fine-grained level. Only applicable when optimizing. <i>This is an expert
    346     option.</i></dd>
    347 
    348 <dt><a name="optimizationpasses"><code><b>-optimizationpasses</b></code></a> <i>n</i></dt>
    349 
    350 <dd>Specifies the number of optimization passes to be performed. By default, a
    351     single pass is performed. Multiple passes may result in further
    352     improvements. If no improvements are found after an optimization pass, the
    353     optimization is ended. Only applicable when optimizing.</dd>
    354 
    355 <dt><a name="assumenosideeffects"><code><b>-assumenosideeffects</b></code></a>
    356     <a href="#classspecification"><i>class_specification</i></a></dt>
    357 
    358 <dd>Specifies methods that don't have any side effects (other than maybe
    359     returning a value). In the optimization step, ProGuard will then remove
    360     calls to such methods, if it can determine that the return values aren't
    361     used. Note that ProGuard will analyze your program code to find such
    362     methods automatically. It will not analyze library code, for which this
    363     option can thus be useful. For example, you could specify the method
    364     <code>System.currentTimeMillis()</code>, so that any idle calls to it will
    365     be removed. Note that ProGuard applies the option to the entire hierarchy
    366     of the specified methods. Only applicable when optimizing. In general,
    367     making assumptions can be dangerous; you can easily break the processed
    368     code. <i>Only use this option if you know what you're doing!</i></dd>
    369 
    370 <dt><a name="allowaccessmodification"><code><b>-allowaccessmodification</b></code></a></dt>
    371 
    372 <dd>Specifies that the access modifiers of classes and class members may be
    373     broadened during processing. This can improve the results of the
    374     optimization step. For instance, when inlining a public getter, it may be
    375     necessary to make the accessed field public too. Although Java's binary
    376     compatibility specifications formally do not require this (cfr. <a href=
    377     "http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html"
    378     >The Java Language Specification, Second Edition</a>, <a href=
    379     "http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html#47259"
    380     >Section 13.4.6</a>), some virtual machines would have problems with the
    381     processed code otherwise. Only applicable when optimizing (and when
    382     obfuscating with the <a
    383     href="#repackageclasses"><code>-repackageclasses</code></a> option).
    384     <p>
    385     <i>Counter-indication:</i> you probably shouldn't use this option when
    386     processing code that is to be used as a library, since classes and class
    387     members that weren't designed to be public in the API may become
    388     public.</dd>
    389 
    390 <dt><a name="mergeinterfacesaggressively"><code><b>-mergeinterfacesaggressively</b></code></a></dt>
    391 
    392 <dd>Specifies that interfaces may be merged, even if their implementing
    393     classes don't implement all interface methods. This can reduce the size of
    394     the output by reducing the total number of classes. Note that Java's
    395     binary compatibility specifications allow such constructs (cfr. <a href=
    396     "http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html"
    397     >The Java Language Specification, Second Edition</a>, <a href=
    398     "http://java.sun.com/docs/books/jls/second_edition/html/binaryComp.doc.html#45347"
    399     >Section 13.5.3</a>), even if they are not allowed in the Java language
    400     (cfr. <a href=
    401     "http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html"
    402     >The Java Language Specification, Second Edition</a>, <a href=
    403     "http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#34031"
    404     >Section 8.1.4</a>). Only applicable when optimizing.
    405     <p>
    406     <i>Counter-indication:</i> setting this option can reduce the performance
    407     of the processed code on some JVMs, since advanced just-in-time
    408     compilation tends to favor more interfaces with fewer implementing
    409     classes. Worse, some JVMs may not be able to handle the resulting code.
    410     Notably:
    411     <ul>
    412     <li>Sun's JRE 1.3 may throw an <code>InternalError</code> when
    413         encountering more than 256 <i>Miranda</i> methods (interface methods
    414         without implementations) in a class.</li>
    415     </ul></dd>
    416 
    417 </dl>
    418 <p>
    419 
    420 <h2><a name="obfuscationoptions">Obfuscation Options</a></h2>
    421 
    422 <dl>
    423 <dt><a name="dontobfuscate"><code><b>-dontobfuscate</b></code></a></dt>
    424 
    425 <dd>Specifies not to obfuscate the input class files. By default, obfuscation
    426     is applied; classes and class members receive new short random names,
    427     except for the ones listed by the various <code>-keep</code> options.
    428     Internal attributes that are useful for debugging, such as source files
    429     names, variable names, and line numbers are removed.</dd>
    430 
    431 <dt><a name="printmapping"><code><b>-printmapping</b></code></a>
    432     [<a href="#filename"><i>filename</i></a>]</dt>
    433 
    434 <dd>Specifies to print the mapping from old names to new names for classes and
    435     class members that have been renamed. The mapping is printed to the
    436     standard output or to the given file. For example, it is required for
    437     subsequent <a href="examples.html#incremental">incremental
    438     obfuscation</a>, or if you ever want to make sense again of <a
    439     href="examples.html#stacktrace">obfuscated stack traces</a>. Only
    440     applicable when obfuscating.</dd>
    441 
    442 <dt><a name="applymapping"><code><b>-applymapping</b></code></a>
    443     <a href="#filename"><i>filename</i></a></dt>
    444 
    445 <dd>Specifies to reuse the given name mapping that was printed out in a
    446     previous obfuscation run of ProGuard. Classes and class members that are
    447     listed in the mapping file receive the names specified along with them.
    448     Classes and class members that are not mentioned receive new names. The
    449     mapping may refer to input classes as well as library classes. This option
    450     can be useful for <a href="examples.html#incremental">incremental
    451     obfuscation</a>, i.e. processing add-ons or small patches to an existing
    452     piece of code. In such cases, you should consider whether you also need
    453     the option <a
    454     href="#useuniqueclassmembernames"><code>-useuniqueclassmembernames</code></a>.
    455     Only a single mapping file is allowed. Only applicable when
    456     obfuscating.</dd>
    457 
    458 <dt><a name="obfuscationdictionary"><code><b>-obfuscationdictionary</b></code></a>
    459     <a href="#filename"><i>filename</i></a></dt>
    460 
    461 <dd>Specifies a text file from which all valid words are used as obfuscated
    462     field and method names. By default, short names like 'a', 'b', etc. are
    463     used as obfuscated names. With an obfuscation dictionary, you can specify
    464     a list of reserved key words, or identifiers with foreign characters, for
    465     instance. White space, punctuation characters, duplicate words, and
    466     comments after a <code><b>#</b></code> sign are ignored. Note that an
    467     obfuscation dictionary hardly improves the obfuscation. Decent compilers
    468     can automatically replace them, and the effect can fairly simply be undone
    469     by obfuscating again with simpler names. The most useful application is
    470     specifying strings that are typically already present in class files (such
    471     as 'Code'), thus reducing the class file sizes just a little bit more.
    472     Only applicable when obfuscating.</dd>
    473 
    474 <dt><a name="classobfuscationdictionary"><code><b>-classobfuscationdictionary</b></code></a>
    475     <a href="#filename"><i>filename</i></a></dt>
    476 
    477 <dd>Specifies a text file from which all valid words are used as obfuscated
    478     class names. The obfuscation dictionary is similar to the one of the
    479     option <a
    480     href="#obfuscationdictionary"><code>-obfuscationdictionary</code></a>.
    481     Only applicable when obfuscating.</dd>
    482 
    483 <dt><a name="packageobfuscationdictionary"><code><b>-packageobfuscationdictionary</b></code></a>
    484     <a href="#filename"><i>filename</i></a></dt>
    485 
    486 <dd>Specifies a text file from which all valid words are used as obfuscated
    487     package names. The obfuscation dictionary is similar to the one of the
    488     option <a
    489     href="#obfuscationdictionary"><code>-obfuscationdictionary</code></a>.
    490     Only applicable when obfuscating.</dd>
    491 
    492 <dt><a name="overloadaggressively"><code><b>-overloadaggressively</b></code></a></dt>
    493 
    494 <dd>Specifies to apply aggressive overloading while obfuscating. Multiple
    495     fields and methods can then get the same names, as long as their arguments
    496     and return types are different (not just their arguments). This option can
    497     make the processed code even smaller (and less comprehensible). Only
    498     applicable when obfuscating.
    499     <p>
    500     <i>Counter-indication:</i> the resulting class files fall within the Java
    501     bytecode specification (cfr. <a href=
    502     "http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html"
    503     >The Java Virtual Machine Specification, Second Edition</a>, first
    504     paragraphs of <a href=
    505     "http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#2877"
    506     >Section 4.5</a> and <a href=
    507     "http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#1513"
    508     >Section 4.6</a>), even though this kind of overloading is not allowed in
    509     the Java language (cfr. <a href=
    510     "http://java.sun.com/docs/books/jls/second_edition/html/j.title.doc.html"
    511     >The Java Language Specification, Second Edition</a>, <a href=
    512     "http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#40898"
    513     >Section 8.3</a> and <a href=
    514     "http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#227768"
    515     >Section 8.4.7</a>). Still, some tools have problems with it. Notably:
    516     <ul>
    517     <li>Sun's JDK 1.2.2 <code>javac</code> compiler produces an exception when
    518         compiling with such a library (cfr. <a href=
    519         "http://bugs.sun.com/view_bug.do?bug_id=4216736">Bug #4216736</a>).
    520         You probably shouldn't use this option for processing libraries.</li>
    521     <li>Sun's JRE 1.4 and later fail to serialize objects with overloaded
    522         primitive fields.</li>
    523     <li>Sun's JRE 1.5 <code>pack200</code> tool reportedly has problems with
    524         overloaded class members.</li>
    525     <li>Google's Dalvik VM can't handle overloaded static fields.</li>
    526     </ul></dd>
    527 
    528 <dt><a name="useuniqueclassmembernames"><code><b>-useuniqueclassmembernames</b></code></a></dt>
    529 
    530 <dd>Specifies to assign the same obfuscated names to class members that have
    531     the same names, and different obfuscated names to class members that have
    532     different names (for each given class member signature). Without the
    533     option, more class members can be mapped to the same short names like 'a',
    534     'b', etc. The option therefore increases the size of the resulting code
    535     slightly, but it ensures that the saved obfuscation name mapping can
    536     always be respected in subsequent incremental obfuscation steps.
    537     <p>
    538     For instance, consider two distinct interfaces containing methods with the
    539     same name and signature. Without this option, these methods may get
    540     different obfuscated names in a first obfuscation step. If a patch is then
    541     added containing a class that implements both interfaces, ProGuard will
    542     have to enforce the same method name for both methods in an incremental
    543     obfuscation step. The original obfuscated code is changed, in order to
    544     keep the resulting code consistent. With this option <i>in the initial
    545     obfuscation step</i>, such renaming will never be necessary.
    546     <p>
    547     This option is only applicable when obfuscating. In fact, if you are
    548     planning on performing incremental obfuscation, you probably want to avoid
    549     shrinking and optimization altogether, since these steps could remove or
    550     modify parts of your code that are essential for later additions.</dd>
    551 
    552 <dt><a name="dontusemixedcaseclassnames"><code><b>-dontusemixedcaseclassnames</b></code></a></dt>
    553 
    554 <dd>Specifies not to generate mixed-case class names while obfuscating. By
    555     default, obfuscated class names can contain a mix of upper-case characters
    556     and lower-case characters. This creates perfectly acceptable and usable
    557     jars. Only if a jar is unpacked on a platform with a case-insensitive
    558     filing system (say, Windows), the unpacking tool may let similarly named
    559     class files overwrite each other. Code that self-destructs when it's
    560     unpacked! Developers who really want to unpack their jars on Windows can
    561     use this option to switch off this behavior. Note that the obfuscated jars
    562     will become larger as a result. Only applicable when obfuscating.</dd>
    563 
    564 <dt><a name="keeppackagenames"><code><b>-keeppackagenames</b></code></a>
    565     [<i><a href="#filters">package_filter</a></i>]</dt>
    566 
    567 <dd>Specifies not obfuscate the given package names. The optional filter is a
    568     comma-separated list of package names. Package names can contain <b>?</b>,
    569     <b>*</b>, and <b>**</b> wildcards, and they can be preceded by the
    570     <b>!</b> negator. Only applicable when obfuscating.</dd>
    571 
    572 <dt><a name="flattenpackagehierarchy"><code><b>-flattenpackagehierarchy</b></code></a>
    573     [<i>package_name</i>]</dt>
    574 
    575 <dd>Specifies to repackage all packages that are renamed, by moving them into
    576     the single given parent package. Without argument or with an empty string
    577     (''), the packages are moved into the root package. This option is one
    578     example of further <a href="examples.html#repackaging">obfuscating package
    579     names</a>. It can make the processed code smaller and less comprehensible.
    580     Only applicable when obfuscating.</dd>
    581 
    582 <dt><a name="repackageclasses"><code><b>-repackageclasses</b></code></a>
    583     [<i>package_name</i>]</dt>
    584 
    585 <dd>Specifies to repackage all class files that are renamed, by moving them
    586     into the single given package. Without argument or with an empty string
    587     (''), the package is removed completely. This option option overrides the
    588     <a
    589     href="#flattenpackagehierarchy"><code>-flattenpackagehierarchy</code></a>
    590     option. It is another example of further <a
    591     href="examples.html#repackaging">obfuscating package names</a>. It can
    592     make the processed code even smaller and less comprehensible. Its
    593     deprecated name is <code>-defaultpackage</code>. Only applicable when
    594     obfuscating.
    595     <p>
    596     <i>Counter-indication:</i> classes that look for resource files in their
    597     package directories will no longer work properly if they are moved
    598     elsewhere. When in doubt, just leave the packaging untouched by not using
    599     this option.</dd>
    600 
    601 <dt><a name="keepattributes"><code><b>-keepattributes</b></code></a>
    602     [<i><a href="#filters">attribute_filter</a></i>]</dt>
    603 
    604 <dd>Specifies any optional attributes to be preserved. The attributes can be
    605     specified with one or more <code>-keepattributes</code> directives. The
    606     optional filter is a comma-separated list of attribute names. Attribute
    607     names can contain <b>?</b>, <b>*</b>, and <b>**</b> wildcards, and they
    608     can be preceded by the <b>!</b> negator. Typical optional attributes are
    609     <code>Exceptions</code>, <code>Signature</code>, <code>Deprecated</code>,
    610     <code>SourceFile</code>, <code>SourceDir</code>,
    611     <code>LineNumberTable</code>, <code>LocalVariableTable</code>,
    612     <code>LocalVariableTypeTable</code>, <code>Synthetic</code>,
    613     <code>EnclosingMethod</code>, <code>RuntimeVisibleAnnotations</code>,
    614     <code>RuntimeInvisibleAnnotations</code>,
    615     <code>RuntimeVisibleParameterAnnotations</code>,
    616     <code>RuntimeInvisibleParameterAnnotations</code>, and
    617     <code>AnnotationDefault</code>. The <code>InnerClasses</code> attribute
    618     name can be specified as well, referring to the source name part of this
    619     attribute. For example, you should at least keep the
    620     <code>Exceptions</code>, <code>InnerClasses</code>, and
    621     <code>Signature</code> attributes
    622     when <a href="examples.html#library">processing a library</a>. You should
    623     also keep the <code>SourceFile</code> and
    624     <code>LineNumberTable</code> attributes
    625     for <a href="examples.html#stacktrace">producing useful obfuscated stack
    626     traces</a>. Finally, you may want
    627     to <a href="examples.html#annotations">keep annotations</a> if your code
    628     depends on them. Only applicable when obfuscating.</dd>
    629 
    630 <dt><a name="keepparameternames"><code><b>-keepparameternames</b></code></a></dt>
    631 
    632 <dd>Specifies to keep the parameter names and types of methods that are kept.
    633     This option actually keeps trimmed versions of the debugging attributes
    634     <code>LocalVariableTable</code> and
    635     <code>LocalVariableTypeTable</code>. It can be useful when
    636     <a href="examples.html#library">processing a library</a>. Some IDEs can
    637     use the information to assist developers who use the library, for example
    638     with tool tips or autocompletion. Only applicable when obfuscating.</dd>
    639 
    640 <dt><a name="renamesourcefileattribute"><code><b>-renamesourcefileattribute</b></code></a>
    641     [<i>string</i>]</dt>
    642 
    643 <dd>Specifies a constant string to be put in the <code>SourceFile</code>
    644     attributes (and <code>SourceDir</code> attributes) of the class files.
    645     Note that the attribute has to be present to start with, so it also has to
    646     be preserved explicitly using the <code>-keepattributes</code> directive.
    647     For example, you may want to have your processed libraries and
    648     applications produce <a href="examples.html#stacktrace">useful obfuscated
    649     stack traces</a>. Only applicable when obfuscating.</dd>
    650 
    651 <dt><a name="adaptclassstrings"><code><b>-adaptclassstrings</b></code></a>
    652     [<i><a href="#filters">class_filter</a></i>]</dt>
    653 
    654 <dd>Specifies that string constants that correspond to class names should be
    655     obfuscated as well. Without a filter, all string constants that correspond
    656     to class names are adapted. With a filter, only string constants in
    657     classes that match the filter are adapted. For example, if your code
    658     contains a large number of hard-coded strings that refer to classes, and
    659     you prefer not to keep their names, you may want to use this option.
    660     Primarily applicable when obfuscating, although corresponding classes are
    661     automatically kept in the shrinking step too.</dd>
    662 
    663 <dt><a name="adaptresourcefilenames"><code><b>-adaptresourcefilenames</b></code></a>
    664     [<i><a href="#filefilters">file_filter</a></i>]</dt>
    665 
    666 <dd>Specifies the resource files to be renamed, based on the obfuscated names
    667     of the corresponding class files (if any). Without a filter, all resource
    668     files that correspond to class files are renamed. With a filter, only
    669     matching files are renamed. For example, see <a
    670     href="examples.html#resourcefiles">processing resource files</a>. Only
    671     applicable when obfuscating.</dd>
    672 
    673 <dt><a name="adaptresourcefilecontents"><code><b>-adaptresourcefilecontents</b></code></a>
    674     [<i><a href="#filefilters">file_filter</a></i>]</dt>
    675 
    676 <dd>Specifies the resource files whose contents are to be updated. Any class
    677     names mentioned in the resource files are renamed, based on the obfuscated
    678     names of the corresponding classes (if any). Without a filter, the
    679     contents of all resource files updated. With a filter, only matching files
    680     are updated. The resource files are parsed and written using the
    681     platform's default character set. You can change this default character set
    682     by setting the environment variable <code>LANG</code> or the Java system
    683     property <code>file.encoding</code>. For an example,
    684     see <a href="examples.html#resourcefiles">processing resource files</a>.
    685     Only applicable when obfuscating.</dd>
    686 
    687 </dl>
    688 <p>
    689 
    690 <h2><a name="preverificationoptions">Preverification Options</a></h2>
    691 
    692 <dl>
    693 <dt><a name="dontpreverify"><code><b>-dontpreverify</b></code></a></dt>
    694 
    695 <dd>Specifies not to preverify the processed class files. By default, class
    696     files are preverified if they are targeted at Java Micro Edition or at
    697     Java 6 or higher. For Java Micro Edition, preverification is required, so
    698     you will need to run an external preverifier on the processed code if you
    699     specify this option. For Java 6, preverification is not required (yet),
    700     but it improves the efficiency of the class loading in the Java Virtual
    701     Machine.</dd>
    702 
    703 <dt><a name="microedition"><code><b>-microedition</b></code></a></dt>
    704 
    705 <dd>Specifies that the processed class files are targeted at Java Micro
    706     Edition. The preverifier will then add the appropriate StackMap
    707     attributes, which are different from the default StackMapTable attributes
    708     for Java Standard Edition. For example, you will need this option if you
    709     are <a href="examples.html#midlets">processing midlets</a>.</dd>
    710 
    711 </dl>
    712 <p>
    713 
    714 <h2><a name="generaloptions">General Options</a></h2>
    715 
    716 <dl>
    717 <dt><a name="verbose"><code><b>-verbose</b></code></a></dt>
    718 
    719 <dd>Specifies to write out some more information during processing. If the
    720     program terminates with an exception, this option will print out the entire
    721     stack trace, instead of just the exception message.</dd>
    722 
    723 <dt><a name="dontnote"><code><b>-dontnote</b></code></a>
    724     [<i><a href="#filters">class_filter</a></i>]</dt>
    725 
    726 <dd>Specifies not to print notes about potential mistakes or omissions in the
    727     configuration, like typos in class names, or like missing options that
    728     might be useful. The optional filter is a regular expression; ProGuard
    729     doesn't print notes about classes with matching names.</dd>
    730 
    731 <dt><a name="dontwarn"><code><b>-dontwarn</b></code></a>
    732     [<i><a href="#filters">class_filter</a></i>]</dt>
    733 
    734 <dd>Specifies not to warn about unresolved references and other important
    735     problems at all. The optional filter is a regular expression; ProGuard
    736     doesn't print warnings about classes with matching names. Ignoring
    737     warnings can be dangerous. For instance, if the unresolved classes or
    738     class members are indeed required for processing, the processed code will
    739     not function properly. <i>Only use this option if you know what you're
    740     doing!</i></dd>
    741 
    742 <dt><a name="ignorewarnings"><code><b>-ignorewarnings</b></code></a></dt>
    743 
    744 <dd>Specifies to print any warnings about unresolved references and other
    745     important problems, but to continue processing in any case. Ignoring
    746     warnings can be dangerous. For instance, if the unresolved classes or
    747     class members are indeed required for processing, the processed code will
    748     not function properly. <i>Only use this option if you know what you're
    749     doing!</i></dd>
    750 
    751 <dt><a name="printconfiguration"><code><b>-printconfiguration</b></code></a>
    752     [<a href="#filename"><i>filename</i></a>]</dt>
    753 
    754 <dd>Specifies to write out the entire configuration that has been parsed, with
    755     included files and replaced variables. The structure is printed to the
    756     standard output or to the given file. This can sometimes be useful for
    757     debugging configurations, or for converting XML configurations into a more
    758     readable format.</dd>
    759 
    760 <dt><a name="dump"><code><b>-dump</b></code></a>
    761     [<a href="#filename"><i>filename</i></a>]</dt>
    762 
    763 <dd>Specifies to write out the internal structure of the class files, after
    764     any processing. The structure is printed to the standard output or to the
    765     given file. For example, you may want to <a
    766     href="examples.html#structure">write out the contents of a given jar
    767     file</a>, without processing it at all.</dd>
    768 
    769 </dl>
    770 <p>
    771 
    772 <h2><a name="classpath">Class Paths</a></h2>
    773 
    774 ProGuard accepts a generalization of class paths to specify input files and
    775 output files. A class path consists of entries, separated by the traditional
    776 path separator (e.g. '<b>:</b>' on Unix, or '<b>;</b>' on Windows platforms).
    777 The order of the entries determines their priorities, in case of duplicates.
    778 <p>
    779 Each input entry can be:
    780 <ul>
    781 <li>A class file or resource file,</li>
    782 <li>A jar file, containing any of the above,</li>
    783 <li>A war file, containing any of the above,</li>
    784 <li>An ear file, containing any of the above,</li>
    785 <li>A zip file, containing any of the above,</li>
    786 <li>A directory (structure), containing any of the above.</li>
    787 </ul>
    788 <p>
    789 The paths of directly specified class files and resource files is ignored, so
    790 class files should generally be part of a jar file, a war file, an ear file, a
    791 zip file, or a directory. In addition, the paths of class files should not have
    792 any additional directory prefixes inside the archives or directories.
    793 
    794 <p>
    795 Each output entry can be:
    796 <ul>
    797 <li>A jar file, in which all processed class files and resource files will be
    798     collected.</li>
    799 <li>A war file, in which any and all of the above will be collected,</li>
    800 <li>An ear file, in which any and all of the above will be collected,</li>
    801 <li>A zip file, in which any and all of the above will be collected,</li>
    802 <li>A directory, in which any and all of the above will be collected.</li>
    803 </ul>
    804 <p>
    805 When writing output entries, ProGuard will generally package the results in a
    806 sensible way, reconstructing the input entries as much as required. Writing
    807 everything to an output directory is the most straightforward option: the
    808 output directory will contain a complete reconstruction of the input entries.
    809 The packaging can be almost arbitrarily complex though: you could process an
    810 entire application, packaged in a zip file along with its documentation,
    811 writing it out as a zip file again. The Examples section shows a few ways
    812 to <a href="examples.html#restructuring">restructure output archives</a>.
    813 <p>
    814 Files and directories can be specified as discussed in the section on <a
    815 href="#filename">file names</a> below.
    816 <p>
    817 In addition, ProGuard provides the possibility to filter the class path
    818 entries and their contents, based on their full relative file names. Each
    819 class path entry can be followed by up to 5 types of <a
    820 href="#filefilters">file filters</a> between parentheses, separated by
    821 semi-colons:
    822 <ul>
    823 <li>A filter for all zip names that are encountered,</li>
    824 <li>A filter for all ear names that are encountered,</li>
    825 <li>A filter for all war names that are encountered,</li>
    826 <li>A filter for all jar names that are encountered,</li>
    827 <li>A filter for all class file names and resource file names that are
    828     encountered.</li>
    829 </ul>
    830 <p>
    831 If fewer than 5 filters are specified, they are assumed to be the latter
    832 filters. Any empty filters are ignored. More formally, a filtered class path
    833 entry looks like this:
    834 <pre>
    835 <i>classpathentry</i><b>(</b>[[[[<i>zipfilter</i><b>;</b>]<i>earfilter</i><b>;</b>]<i>warfilter</i><b>;</b>]<i>jarfilter</i><b>;</b>]<i>filefilter</i><b>)</b>
    836 </pre>
    837 <p>
    838 Square brackets "[]" mean that their contents are optional.
    839 <p>
    840 For example, "<code>rt.jar(java/**.class,javax/**.class)</code>" matches all
    841 class files in the <code>java</code> and <code>javax</code> directories inside
    842 the <code>rt</code> jar.
    843 <p>
    844 For example, "<code>input.jar(!**.gif,images/**)</code>" matches all files in
    845 the <code>images</code> directory inside the <code>input</code> jar, except
    846 gif files.
    847 <p>
    848 Note that the different filters are applied to all corresponding file types,
    849 irrespective of their nesting levels in the input; they are orthogonal.
    850 <p>
    851 For example,
    852 "<code>input.war(lib/**.jar,support/**.jar;**.class,**.gif)</code>" only
    853 considers jar files in the <code>lib</code> and <code>support</code>
    854 directories in the <code>input</code> war, not any other jar files. It then
    855 matches all class files and gif files that are encountered.
    856 <p>
    857 The filters allow for an almost infinite number of packaging and repackaging
    858 possibilities. The Examples section provides a few more examples
    859 for <a href="examples.html#filtering">filtering input and output</a>.
    860 <p>
    861 
    862 <h2><a name="filename">File Names</a></h2>
    863 
    864 ProGuard accepts absolute paths and relative paths for the various file names
    865 and directory names. A relative path is interpreted as follows:
    866 <ul>
    867 <li>relative to the base directory, if set, or otherwise</li>
    868 <li>relative to the configuration file in which it is specified, if any, or
    869     otherwise</li>
    870 <li>relative to the working directory.</li>
    871 </ul>
    872 <p>
    873 The names can contain Java system properties delimited by '<b>&lt;</b>' and
    874 '<b>&gt;</b>'. The system properties
    875 are automatically replaced by their respective values.
    876 <p>
    877 For example, <code>&lt;java.home&gt;/lib/rt.jar</code> will automatically be
    878 expanded to something like <code>/usr/local/java/jdk/jre/lib/rt.jar</code>.
    879 Similarly, <code>&lt;user.home&gt;</code> will be expanded to the user's home
    880 directory, and <code>&lt;user.dir&gt;</code> will be expanded to the current
    881 working directory.
    882 <p>
    883 Names with special characters like spaces and parentheses must be quoted with
    884 single or double quotes. Note that each file name in a list of names has to be
    885 quoted individually. Also note that the quotes themselves may need to be
    886 escaped when used on the command line, to avoid them being gobbled by the
    887 shell.
    888 <p>
    889 For example, on the command line, you could use an option like <code>'-injars
    890 "my program.jar":"/your directory/your program.jar"'</code>.
    891 <p>
    892 
    893 <h2><a name="filefilters">File Filters</a></h2>
    894 
    895 Like general <a href="#filters">filters</a>, a file filter is a
    896 comma-separated list of file names that can contain wildcards. Only files with
    897 matching file names are read (in the case of input jars), or written (in the
    898 case of output jars). The following wildcards are supported:
    899 
    900 <table cellspacing="10">
    901 <tr><td valign="top"><code><b>?</b></code></td>
    902     <td>matches any single character in a file name.</td></tr>
    903 <tr><td valign="top"><code><b>*</b></code></td>
    904     <td>matches any part of a filename not containing the directory
    905         separator.</td></tr>
    906 <tr><td valign="top"><code><b>**</b></code></td>
    907     <td>matches any part of a filename, possibly containing any number of
    908         directory separators.</td></tr>
    909 </table>
    910 
    911 For example, "<code>java/**.class,javax/**.class</code>" matches all
    912 class files in the <code>java</code> and <code>javax</code>.
    913 <p>
    914 
    915 Furthermore, a file name can be preceded by an exclamation mark '<b>!</b>' to
    916 <i>exclude</i> the file name from further attempts to match with
    917 <i>subsequent</i> file names.
    918 <p>
    919 For example, "<code>!**.gif,images/**</code>" matches all files in the
    920 <code>images</code> directory, except gif files.
    921 <p>
    922 The Examples section provides a few more examples for <a
    923 href="examples.html#filtering">filtering input and output</a>.
    924 
    925 <h2><a name="filters">Filters</a></h2>
    926 
    927 ProGuard offers options with filters for many different aspects of the
    928 configuration: names of files, directories, classes, packages, attributes,
    929 optimizations, etc. 
    930 <p>
    931 A filter is a list of comma-separated names that can contain wildcards. Only
    932 names that match an item on the list pass the filter. The supported wildcards
    933 depend on the type of names for which the filter is being used, but the
    934 following wildcards are typical:
    935 
    936 <table cellspacing="10">
    937 <tr><td valign="top"><code><b>?</b></code></td>
    938     <td>matches any single character in a name.</td></tr>
    939 <tr><td valign="top"><code><b>*</b></code></td>
    940     <td>matches any part of a name not containing the package separator or
    941         directory separator.</td></tr>
    942 <tr><td valign="top"><code><b>**</b></code></td>
    943     <td>matches any part of a name, possibly containing any number of
    944         package separators or directory separators.</td></tr>
    945 </table>
    946 
    947 For example, "<code>foo,*bar</code>" matches the name <code>foo</code> and
    948 all names ending with <code>bar</code>.
    949 <p>
    950 
    951 Furthermore, a name can be preceded by a negating exclamation mark '<b>!</b>'
    952 to <i>exclude</i> the name from further attempts to match
    953 with <i>subsequent</i> names. So, if a name matches an item in the filter, it
    954 is accepted or rejected right away, depending on whether the item has a
    955 negator. If the name doesn't match the item, it is tested against the next
    956 item, and so on. It if doesn't match any items, it is accepted or rejected,
    957 depending on the whether the last item has a negator or not.
    958 <p>
    959 For example, "<code>!foobar,*bar</code>" matches all names ending with
    960 <code>bar</code>, except <code>foobar</code>.
    961 <p>
    962 
    963 <h2><a name="keepoverview">Overview of <code>Keep</code> Options</a></h2>
    964 
    965 The various <code>-keep</code> options for shrinking and obfuscation may seem
    966 a bit confusing at first, but there's actually a pattern behind them. The
    967 following table summarizes how they are related:
    968 <p>
    969 
    970 <table cellpadding="5">
    971 
    972 <tr>
    973 <th>Keep</th>
    974 <td>From being removed or renamed</td>
    975 <td>From being renamed</td>
    976 </tr>
    977 
    978 <tr>
    979 <td>Classes and class members</td>
    980 <td bgcolor="#E0E0E0"><a href="#keep"><code>-keep</code></a></td>
    981 <td bgcolor="#E0E0E0"><a href="#keepnames"><code>-keepnames</code></a></td>
    982 </tr>
    983 
    984 <tr>
    985 <td>Class members only</td>
    986 <td bgcolor="#E0E0E0"><a href="#keepclassmembers"><code>-keepclassmembers</code></a></td>
    987 <td bgcolor="#E0E0E0"><a href="#keepclassmembernames"><code>-keepclassmembernames</code></a></td>
    988 </tr>
    989 
    990 <tr>
    991 <td>Classes and class members, if class members present</td>
    992 <td bgcolor="#E0E0E0"><a href="#keepclasseswithmembers"><code>-keepclasseswithmembers</code></a></td>
    993 <td bgcolor="#E0E0E0"><a href="#keepclasseswithmembernames"><code>-keepclasseswithmembernames</code></a></td>
    994 </tr>
    995 
    996 </table>
    997 <p>
    998 
    999 Each of these <code>-keep</code> options is of course followed by a
   1000 <a href="#classspecification">specification</a> of the classes and class
   1001 members (fields and methods) to which it should be applied.
   1002 <p>
   1003 If you're not sure which option you need, you should probably simply use
   1004 <code>-keep</code>. It will make sure the specified classes and class members
   1005 are not removed in the shrinking step, and not renamed in the obfuscation step.
   1006 <p>
   1007 <table>
   1008 <tr><td valign="top">
   1009 <img src="attention.gif" width="64" height="64"alt="attention" />
   1010 </td><td>
   1011 Always remember:
   1012 <ul>
   1013 <li>Specifying a class without class members only preserves the class as an
   1014     entry point &mdash; any class members may then still be removed, optimized,
   1015     or obfuscated.</li>
   1016 <li>Specifying a class member only preserves the class member as an entry
   1017     point &mdash; any associated code may still be optimized and adapted.</li>
   1018 </ul>
   1019 </td></tr>
   1020 </table>
   1021 <p>
   1022 
   1023 <h2><a name="keepoptionmodifiers">Keep Option Modifiers</a></h2>
   1024 
   1025 <dl>
   1026 <dt><a name="allowshrinking"><code><b>allowshrinking</b></code></a></dt>
   1027 
   1028 <dd>Specifies that the entry points specified in the <a href="#keep">-keep</a>
   1029     option may be shrunk, even if they have to be preserved otherwise. That
   1030     is, the entry points may be removed in the shrinking step, but if they are
   1031     necessary after all, they may not be optimized or obfuscated.</dd>
   1032 
   1033 <dt><a name="allowoptimization"><code><b>allowoptimization</b></code></a></dt>
   1034 
   1035 <dd>Specifies that the entry points specified in the <a href="#keep">-keep</a>
   1036     option may be optimized, even if they have to be preserved otherwise. That
   1037     is, the entry points may be altered in the optimization step, but they may
   1038     not be removed or obfuscated. This modifier is only useful for achieving
   1039     unusual requirements.</dd>
   1040 
   1041 <dt><a name="allowobfuscation"><code><b>allowobfuscation</b></code></a></dt>
   1042 
   1043 <dd>Specifies that the entry points specified in the <a href="#keep">-keep</a>
   1044     option may be obfuscated, even if they have to be preserved otherwise. That
   1045     is, the entry points may be renamed in the obfuscation step, but they may
   1046     not be removed or optimized. This modifier is only useful for achieving
   1047     unusual requirements.</dd>
   1048 
   1049 </dl>
   1050 <p>
   1051 
   1052 <h2><a name="classspecification">Class Specifications</a></h2>
   1053 
   1054 A class specification is a template of classes and class members (fields and
   1055 methods). It is used in the various <code>-keep</code> options and in the
   1056 <code>-assumenosideeffects</code> option. The corresponding option is only
   1057 applied to classes and class members that match the template.
   1058 <p>
   1059 The template was designed to look very Java-like, with some extensions for
   1060 wildcards. To get a feel for the syntax, you should probably look at the <a
   1061 href="examples.html">examples</a>, but this is an attempt at a complete formal
   1062 definition:
   1063 <p>
   1064 
   1065 <pre>
   1066 [<b>@</b><i>annotationtype</i>] [[<b>!</b>]<b>public</b>|<b>final</b>|<b>abstract</b>|<b>@</b> ...] [<b>!</b>]<b>interface</b>|<b>class</b>|<b>enum</b> <i>classname</i>
   1067     [<b>extends</b>|<b>implements</b> [<b>@</b><i>annotationtype</i>] <i>classname</i>]
   1068 [<b>{</b>
   1069     [<b>@</b><i>annotationtype</i>] [[<b>!</b>]<b>public</b>|<b>private</b>|<b>protected</b>|<b>static</b>|<b>volatile</b>|<b>transient</b> ...] <b>&lt;fields&gt;</b> |
   1070                                                                       (<i>fieldtype fieldname</i>)<b>;</b>
   1071     [<b>@</b><i>annotationtype</i>] [[<b>!</b>]<b>public</b>|<b>private</b>|<b>protected</b>|<b>static</b>|<b>synchronized</b>|<b>native</b>|<b>abstract</b>|<b>strictfp</b> ...] <b>&lt;methods&gt;</b> |
   1072                                                                                            <b>&lt;init&gt;(</b><i>argumenttype,...</i><b>)</b> |
   1073                                                                                            <i>classname</i><b>(</b><i>argumenttype,...</i><b>)</b> |
   1074                                                                                            (<i>returntype methodname</i><b>(</b><i>argumenttype,...</i><b>)</b>)<b>;</b>
   1075     [<b>@</b><i>annotationtype</i>] [[<b>!</b>]<b>public</b>|<b>private</b>|<b>protected</b>|<b>static</b> ... ] <b>*;</b>
   1076     ...
   1077 <b>}</b>]
   1078 </pre>
   1079 <p>
   1080 Square brackets "[]" mean that their contents are optional. Ellipsis dots
   1081 "..." mean that any number of the preceding items may be specified. A vertical
   1082 bar "|" delimits two alternatives. Non-bold parentheses "()" just group parts
   1083 of the specification that belong together. The indentation tries to clarify
   1084 the intended meaning, but white-space is irrelevant in actual configuration
   1085 files.
   1086 <p>
   1087 <ul class="spacious">
   1088 
   1089 <li>The <code><b>class</b></code> keyword refers to any interface or class.
   1090     The <code><b>interface</b></code> keyword restricts matches to interface
   1091     classes. The <code><b>enum</b></code> keyword restricts matches to
   1092     enumeration classes. Preceding the <code><b>interface</b></code> or
   1093     <code><b>enum</b></code> keywords by a <code><b>!</b></code> restricts
   1094     matches to classes that are not interfaces or enumerations,
   1095     respectively.</li>
   1096 
   1097 <li>Every <i>classname</i> must be fully qualified, e.g.
   1098     <code>java.lang.String</code>. Class names may be specified as regular
   1099     expressions containing the following wildcards:
   1100 
   1101 <table cellspacing="10">
   1102 
   1103 <tr><td valign="top"><code><b>?</b></code></td>
   1104 
   1105 <td>matches any single character in a class name, but not the package
   1106     separator. For example, "<code>mypackage.Test?</code>" matches
   1107     "<code>mypackage.Test1</code>" and "<code>mypackage.Test2</code>", but not
   1108     "<code>mypackage.Test12</code>".</td></tr>
   1109 
   1110 <tr><td valign="top"><code><b>*</b></code></td>
   1111 
   1112 <td>matches any part of a class name not containing the package separator. For
   1113     example, "<code>mypackage.*Test*</code>" matches
   1114     "<code>mypackage.Test</code>" and
   1115     "<code>mypackage.YourTestApplication</code>", but not
   1116     "<code>mypackage.mysubpackage.MyTest</code>". Or, more generally,
   1117     "<code>mypackage.*</code>" matches all classes in
   1118     "<code>mypackage</code>", but not in its subpackages.</td></tr>
   1119 
   1120 <tr><td valign="top"><code><b>**</b></code></td>
   1121 
   1122 <td>matches any part of a class name, possibly containing any number of
   1123     package separators. For example, "<code>**.Test</code>" matches all
   1124     <code>Test</code> classes in all packages except the root package. Or,
   1125     "<code>mypackage.**</code>" matches all classes in
   1126     "<code>mypackage</code>" and in its subpackages.</td></tr>
   1127 
   1128 </table>
   1129 
   1130     For additional flexibility, class names can actually be comma-separated
   1131     lists of class names, with optional <code><b>!</b></code> negators, just
   1132     like file name filters. This notation doesn't look very Java-like, so it
   1133     should be used with moderation.
   1134     <p>
   1135     For convenience and for backward compatibility, the class name
   1136     <code><b>*</b></code> refers to any class, irrespective of its package.</li>
   1137 
   1138 <li>The <code><b>extends</b></code> and <code><b>implements</b></code>
   1139     specifications are typically used to restrict classes with wildcards. They
   1140     are currently equivalent, specifying that only classes extending or
   1141     implementing the given class qualify. Note that the given class itself is
   1142     not included in this set. If required, it should be specified in a
   1143     separate option.</li>
   1144 
   1145 <li>The <code><b>@</b></code> specifications can be used to restrict classes
   1146     and class members to the ones that are annotated with the specified
   1147     annotation types. An <i>annotationtype</i> is specified just like a
   1148     <i>classname</i>.</li>
   1149 
   1150 <li>Fields and methods are specified much like in Java, except that method
   1151     argument lists don't contain argument names (just like in other tools
   1152     like <code>javadoc</code> and <code>javap</code>). The specifications can
   1153     also contain the following catch-all wildcards:
   1154 
   1155 <table cellspacing="10">
   1156 
   1157 <tr><td valign="top"><code><b>&lt;init&gt;</b></code></td>
   1158 <td>matches any constructor.</td></tr>
   1159 
   1160 <tr><td valign="top"><code><b>&lt;fields&gt;</b></code></td>
   1161 <td>matches any field.</td></tr>
   1162 
   1163 <tr><td valign="top"><code><b>&lt;methods&gt;</b></code></td>
   1164 <td>matches any method.</td></tr>
   1165 
   1166 <tr><td valign="top"><code><b>*</b></code></td>
   1167 <td>matches any field or method.</td></tr>
   1168 
   1169 </table>
   1170 
   1171     Note that the above wildcards don't have return types. Only the
   1172     <code><b>&lt;init&gt;</b></code> wildcard has an argument list.
   1173     <p>
   1174 
   1175     Fields and methods may also be specified using regular expressions. Names
   1176     can contain the following wildcards:
   1177 
   1178 <table cellspacing="10">
   1179 <tr><td valign="top"><code><b>?</b></code></td>
   1180     <td>matches any single character in a method name.</td></tr>
   1181 <tr><td valign="top"><code><b>*</b></code></td>
   1182     <td>matches any part of a method name.</td></tr>
   1183 </table>
   1184 
   1185     Types in descriptors can contain the following wildcards:
   1186 
   1187 <table cellspacing="10">
   1188 <tr><td valign="top"><code><b>%</b></code></td>
   1189     <td>matches any primitive type ("<code>boolean</code>", "<code>int</code>",
   1190         etc, but not "<code>void</code>").</td></tr>
   1191 <tr><td valign="top"><code><b>?</b></code></td>
   1192     <td>matches any single character in a class name.</td></tr>
   1193 <tr><td valign="top"><code><b>*</b></code></td>
   1194     <td>matches any part of a class name not containing the package                     separator.</td></tr>
   1195 <tr><td valign="top"><code><b>**</b></code></td>
   1196     <td>matches any part of a class name, possibly containing any number of
   1197         package separators.</td></tr>
   1198 <tr><td valign="top"><code><b>***</b></code></td>
   1199     <td>matches any type (primitive or non-primitive, array or
   1200         non-array).</td></tr>
   1201 <tr><td valign="top"><code><b>...</b></code></td>
   1202     <td>matches any number of arguments of any type.</td></tr>
   1203 
   1204 </table>
   1205 
   1206     Note that the <code>?</code>, <code>*</code>, and <code>**</code>
   1207     wildcards will never match primitive types. Furthermore, only the
   1208     <code>***</code> wildcards will match array types of any dimension. For
   1209     example, "<code>** get*()</code>" matches "<code>java.lang.Object
   1210     getObject()</code>", but not "<code>float getFloat()</code>", nor
   1211     "<code>java.lang.Object[] getObjects()</code>".</li>
   1212 
   1213 <li>Constructors can also be specified using their short class names (without
   1214     package) or using their full class names. As in the Java language, the
   1215     constructor specification has an argument list, but no return type.</li>
   1216 
   1217 <li>The class access modifiers and class member access modifiers are typically
   1218     used to restrict wildcarded classes and class members. They specify that
   1219     the corresponding access flags have to be set for the member to match. A
   1220     preceding <code><b>!</b></code> specifies that the corresponding access
   1221     flag should be unset.
   1222     <p>
   1223     Combining multiple flags is allowed (e.g. <code>public static</code>). It
   1224     means that both access flags have to be set (e.g. <code>public</code>
   1225     <i>and</i> <code>static</code>), except when they are conflicting, in
   1226     which case at least one of them has to be set (e.g. at least
   1227     <code>public</code>
   1228     <i>or</i> <code>protected</code>).
   1229     <p>
   1230     ProGuard supports the additional modifiers <code><b>synthetic</b></code>,
   1231     <code><b>bridge</b></code>, and <code><b>varargs</b></code>, which may be
   1232     set by compilers.</li>
   1233 
   1234 </ul>
   1235 
   1236 <hr />
   1237 <noscript><div><a target="_top" href="../index.html" class="button">Show menu</a></div></noscript>
   1238 <address>
   1239 Copyright &copy; 2002-2011
   1240 <a target="other" href="http://www.lafortune.eu/">Eric Lafortune</a>.
   1241 </address>
   1242 </body>
   1243 </html>
   1244