Before you can use the proguard
task, you have to tell Ant about
this new task. The easiest way is to add the following line to your
build.xml
file:
<taskdef resource="proguard/ant/task.properties" classpath="/usr/local/java/proguard/lib/proguard.jar" />
Please make sure the class path is set correctly for your system.
There are three ways to configure the ProGuard task: using an external configuration file, using embedded ProGuard configuration options, or using the equivalent XML configuration tags. These three ways can be combined, depending on practical circumstances and personal preference.
configuration
attribute of your
proguard
task. Your ant build file will then look like this:
<taskdef resource="proguard/ant/task.properties" classpath="/usr/local/java/proguard/lib/proguard.jar" /> <proguard configuration="myconfigfile.pro"/>
This is a convenient option if you prefer ProGuard's configuration style over XML, if you want to keep your build file small, or if you have to share your configuration with developers who don't use Ant.
proguard
task
(the PCDATA area). Your Ant build file will then look like this:
<taskdef resource="proguard/ant/task.properties" classpath="/usr/local/java/proguard/lib/proguard.jar" /> <proguard> -libraryjars ${java.home}/lib/rt.jar -injars in.jar -outjars out.jar -keepclasseswithmembers public class * { public static void main(java.lang.String[]); } </proguard>
Some minor syntactical changes are required in order to conform with the XML standard.
Firstly, the #
character cannot be used for comments in an XML
file. Comments must be enclosed by an opening <!--
and a
closing -->
. All occurrences of the #
character
can be removed.
Secondly, the use of <
and >
characters would
upset the structure of the XML build file. Environment variables are now
enclosed by an opening ${
and a closing }
. This
syntax also allows you to use Ant properties within the ProGuard
configuration. Other occurrences of <
and >
have to be encoded as <
and >
.
examples/ant
directory of the ProGuard distribution.
<proguard>
task and the
<proguardconfiguration>
task can have the following
attributes (only for <proguard>
) and nested
elements:
configuration
= "filename"configuration
element.skipnonpubliclibraryclasses
= "boolean"
(default = true)skipnonpubliclibraryclassmembers
= "boolean"
(default = true)target
= "version"
(default = none)forceprocessing
= "boolean"
(default = false)printseeds
= "boolean or filename"
(default = false)keep
commands, to the standard output or to the given file.shrink
= "boolean"
(default = true)printusage
= "boolean or filename"
(default = false)optimize
= "boolean"
(default = true)optimizationpasses
= "n"
(default = 1)allowaccessmodification
= "boolean"
(default = false)mergeinterfacesaggressively
= "boolean"
(default = false)obfuscate
= "boolean"
(default = true)printmapping
= "boolean or filename"
(default = false)applymapping
= "filename"
(default = none)obfuscationdictionary
= "filename"
(default = none)classobfuscationdictionary
= "filename"
(default = none)packageobfuscationdictionary
= "filename"
(default = none)overloadaggressively
= "boolean"
(default = false)useuniqueclassmembernames
= "boolean"
(default = false)usemixedcaseclassnames
= "boolean"
(default = true)flattenpackagehierarchy
= "package_name"
(default = none)repackageclasses
= "package_name"
(default = none)renamesourcefileattribute
= "string"
(default = none)SourceFile
attributes.preverify
= "boolean"
(default = true)microedition
= "boolean"
(default = false)verbose
= "boolean"
(default = false)note
= "boolean"
(default = true)warn
= "boolean"
(default = true)ignorewarnings
= "boolean"
(default = false)printconfiguration
= "boolean or filename"
(default = false)dump
= "boolean or filename"
(default = false)<injar
class_path
/>
<outjar
class_path
/>
<libraryjar
class_path
/>
<keep
modifiers
class_specification
>
class_member_specifications
</keep>
<keepclassmembers
modifiers
class_specification
>
class_member_specifications
</keepclassmembers>
<keepclasseswithmembers
modifiers
class_specification
>
class_member_specifications
</keepclasseswithmembers>
<keepnames
class_specification
>
class_member_specifications
</keepnames>
<keepclassmembernames
class_specification
>
class_member_specifications
</keepclassmembernames>
<keepclasseswithmembernames
class_specification
>
class_member_specifications
</keepclasseswithmembernames>
<whyareyoukeeping
class_specification
>
class_member_specifications
</whyareyoukeeping>
<assumenosideeffects
class_specification
>
class_member_specifications
</assumenosideeffects>
<keepattribute name =
"attribute_name"
/>
<adaptresourcefilenames filter =
"filter"
/>
<adaptresourcefilecontents filter =
"filter"
/>
<configuration refid =
"ref_id"
/>
<proguardconfiguration>
task (or
<proguard>
task) with the attribute id
=
"ref_id". Note that only the nested elements of this configuration
are considered, not the attributes. Also note: for reading ProGuard-style
configuration files, use the configuration
attribute.path
= "path"location
= "name" (or file
= "name", or dir
= "name", or
name
= "name")refid
= "ref_id"id
= "ref_id".filter
=
"filter"jarfilter
=
"filter"warfilter
=
"filter"earfilter
=
"filter"zipfilter
=
"filter"allowshrinking
= "boolean"
(default = false)allowoptimization
= "boolean"
(default = false)allowobfuscation
= "boolean"
(default = false)access
= "access_modifiers"type
= "type"name
= "class_name"extends
= "class_name"implements
= "class_name"<field
class_member_specification
/>
<method
class_member_specification
/>
<constructor
class_member_specification
/>
access
= "access_modifiers"type
= "type"parameters
attribute is specified.name
= "name"parameters
= "parameters"type
attribute is
specified.