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 can be
specified with the usual Ant style ${...}
, instead of the ProGuard
style <...>
. Other occurrences of <
and
>
have to be encoded as <
and
>
respectively.
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 = false)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)keepparameternames
= "boolean"
(default = false)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
/>
<keepdirectory name =
"directory_name"
/>
<keepdirectories filter =
"directory_filter"
/>
<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>
<optimization name =
"optimization_name"
/>
<optimizations filter =
""optimization_filter"
/>
<keeppackagename name =
"package_name"
/>
<keeppackagenames filter =
"package_filter"
/>
<keepattribute name =
"attribute_name"
/>
<keepattributes filter =
"attribute_filter"
/>
<adaptclassstrings filter =
"class_filter"
/>
<adaptresourcefilenames filter =
"file_filter"
/>
<adaptresourcefilecontents filter =
"file_filter"
/>
<dontnote filter =
"class_filter"
/>
<dontwarn filter =
"class_filter"
/>
<configuration refid =
"ref_id"
/>
<configuration file =
"name"
/>
<proguardconfiguration>
task (or
<proguard>
task) with attribute id
=
"ref_id". Only the nested elements of this configuration are
considered, not the attributes.
The second form includes the ProGuard-style configuration from the specified
file. The element is actually a fileset
element and supports
all of its attributes and nested elements, including multiple files.
path
elements, so they can have any of the
standard path
attributes and nested elements. The most common
attributes are:
path
= "path"location
= "name" (or file
= "name", or dir
= "name", or
name
= "name")refid
= "ref_id"id
= "ref_id".filter
=
"file_filter"jarfilter
=
"file_filter"warfilter
=
"file_filter"earfilter
=
"file_filter"zipfilter
=
"file_filter"allowshrinking
= "boolean"
(default = false)allowoptimization
= "boolean"
(default = false)allowobfuscation
= "boolean"
(default = false)access
= "access_modifiers"annotation
= "annotation_name"type
= "type"name
= "class_name"extendsannotation
= "annotation_name"extends
= "class_name"implements
= "class_name"<field
class_member_specification
/>
<method
class_member_specification
/>
<constructor
class_member_specification
/>
access
= "access_modifiers"annotation
= "annotation_name"type
= "type"parameters
attribute is specified.name
= "name"parameters
= "parameters"type
attribute is
specified.