Products
Products
Open-source Technology
Solutions
Resources
Company
ProGuard can be run as a task in the Java-based build tool Ant (version 1.8 or higher).
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-ant.jar" />
Please make sure the class path is set correctly for your system.
There are three ways to configure the ProGuard task:
These three ways can be combined, depending on practical circumstances and personal preference.
The simplest way to use the ProGuard task in an Ant build file is to keep your ProGuard configuration file, and include it from Ant. You can include your ProGuard configuration file by setting the 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-ant.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.
Instead of keeping an external ProGuard configuration file, you can also copy the contents of the file into the nested text of the 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-ant.jar" />
<proguard>
-injars in.jar
-outjars out.jar
-libraryjars ${java.home}/lib/rt.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.
If you really prefer a full-blown XML configuration, you can replace the ProGuard configuration options by XML configuration tags. The resulting configuration will be equivalent, but much more verbose and difficult to read, as XML goes. The remainder of this page presents the supported tags. For a more extensive discussion of their meaning, please consult the traditional Usage section. You can find some sample configuration files in the examples/ant
directory of the ProGuard distribution.
The <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)android
= "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)addconfigurationdebugging
= "boolean" (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>
<assumenoexternalsideeffects
class_specification >
class_member_specifications </assumenoexternalsideeffects>
<assumenoescapingparameters
class_specification >
class_member_specifications </assumenoescapingparameters>
<assumenoexternalreturnvalues
class_specification >
class_member_specifications </assumenoexternalreturnvalues>
<assumevalues
class_specification >
class_member_specifications </assumevalues>
<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.The jar elements are 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".In addition, the jar elements can have ProGuard-style filter attributes:
filter
= "file_filter"apkfilter
= "file_filter"aabfilter
= "file_filter"jarfilter
= "file_filter"aarfilter
= "file_filter"warfilter
= "file_filter"earfilter
= "file_filter"jmodfilter
= "file_filter"zipfilter
= "file_filter"The keep tags can have the following modifier attributes:
includedescriptorclasses
= "boolean" (default = false)allowshrinking
= "boolean" (default = false)allowoptimization
= "boolean" (default = false)allowobfuscation
= "boolean" (default = false)The keep tags can have the following class_specification attributes and class_member_specifications nested elements:
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 />
The class member tags can have the following class_member_specification attributes:
access
= "access_modifiers"annotation
= "annotation_name"type
= "type"parameters
attribute is specified.name
= "name"parameters
= "parameters"type
attribute is specified.values
= "values"