Ant与Proguard集中
示例:
<taskdef resource="proguard/ant/task.properties"
classpath="/usr/local/java/proguard/lib/proguard.jar" />
<target name="proguard">
classpath="/usr/local/java/proguard/lib/proguard.jar" />
<target name="proguard">
<
proguard configuration="myconfigfile.pro"/>
</target>
可以将proguard想象成自定义的命令标签,和jar、javac、copy等命令一样
Ant task
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.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.
1. An external ProGuard configuration file 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.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.
2. Embedded ProGuard configuration options 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.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.
3. XML configuration tags 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.
Task attributes and nested elements
The <proguard>
task and the <proguardconfiguration>
task can have the following attributes (only for <proguard>
) and nested elements:
configuration = "filename"
Read and merge options from the given ProGuard-style configuration file. Note: for reading multiple configuration files or XML-style configurations, use the configuration element.
skipnonpubliclibraryclasses = "boolean"
(default = false) Ignore non-public library classes.
skipnonpubliclibraryclassmembers = "boolean"
(default = true) Ignore package visible library class members.
target = "version"
(default = none) Set the given version number in the processed classes.
forceprocessing = "boolean"
(default = false) Process the input, even if the output seems up to date.
printseeds = "boolean or filename"
(default = false) List classes and class members matched by the various keep commands, to the standard output or to the given file.
shrink = "boolean"
(default = true) Shrink the input class files.
printusage = "boolean or filename"
(default = false) List dead code of the input class files, to the standard output or to the given file.
optimize = "boolean"
(default = true) Optimize the input class files.
optimizationpasses = "n"
(default = 1) The number of optimization passes to be performed.
allowaccessmodification = "boolean"
(default = false) Allow the access modifiers of classes and class members to be modified, while optimizing.
mergeinterfacesaggressively = "boolean"
(default = false) Allow any interfaces to be merged, while optimizing.
obfuscate = "boolean"
(default = true) Obfuscate the input class files.
printmapping = "boolean or filename"
(default = false) Print the mapping from old names to new names for classes and class members that have been renamed, to the standard output or to the given file.
applymapping = "filename"
(default = none) Reuse the given mapping, for incremental obfuscation.
obfuscationdictionary = "filename"
(default = none) Use the words in the given text file as obfuscated field names and method names.
classobfuscationdictionary = "filename"
(default = none) Use the words in the given text file as obfuscated class names.
packageobfuscationdictionary = "filename"
(default = none) Use the words in the given text file as obfuscated package names.
overloadaggressively = "boolean"
(default = false) Apply aggressive overloading while obfuscating.
useuniqueclassmembernames = "boolean"
(default = false) Ensure uniform obfuscated class member names for subsequent incremental obfuscation.
usemixedcaseclassnames = "boolean"
(default = true) Generate mixed-case class names while obfuscating.
flattenpackagehierarchy = "package_name"
(default = none) Repackage all packages that are renamed into the single given parent package.
repackageclasses = "package_name"
(default = none) Repackage all class files that are renamed into the single given package.
keepparameternames = "boolean"
(default = false) Keep the parameter names and types of methods that are kept.
renamesourcefileattribute = "string"
(default = none) Put the given constant string in the SourceFile attributes.
preverify = "boolean"
(default = true) Preverify the processed class files if they are targeted at Java Micro Edition or at Java 6 or higher.
microedition = "boolean"
(default = false) Target the processed class files at Java Micro Edition.
verbose = "boolean"
(default = false) Write out some more information during processing.
note = "boolean"
(default = true) Print notes about potential mistakes or omissions in the configuration. Use the nested element dontnote for more fine-grained control.
warn = "boolean"
(default = true) Print warnings about unresolved references. Use the nested element dontwarn for more fine-grained control. Only use this option if you know what you're doing!
ignorewarnings = "boolean"
(default = false) Print warnings about unresolved references, but continue processing anyhow. Only use this option if you know what you're doing!
printconfiguration = "boolean or filename"
(default = false) Write out the entire configuration in traditional ProGuard style, to the standard output or to the given file. Useful to replace unreadable XML configurations.
dump = "boolean or filename"
(default = false) Write out the internal structure of the processed class files, to the standard output or to the given file.
<injar class_path />
Specifies the program jars (or aars, wars, ears, zips, apks, or directories).
<outjar class_path />
Specifies the names of the output jars (or aars, wars, ears, zips, apks, or directories).
<libraryjar class_path />
Specifies the library jars (or aars, wars, ears, zips, apks, or directories).
<keepdirectory name = “directory_name" /> <keepdirectories filter = "directory_filter" />
Keep the specified directories in the output jars (or aars, wars, ears, zips, apks, or directories).
<keep modifiers class_specification > class_member_specifications </keep>
Preserve the specified classes and class members.
<keepclassmembers modifiers class_specification > class_member_specifications </keepclassmembers>
Preserve the specified class members, if their classes are preserved as well.
<keepclasseswithmembers modifiers class_specification > class_member_specifications </keepclasseswithmembers>
Preserve the specified classes and class members, if all of the specified class members are present.
<keepnames class_specification > class_member_specifications </keepnames>
Preserve the names of the specified classes and class members (if they aren't removed in the shrinking step).
<keepclassmembernames class_specification > class_member_specifications </keepclassmembernames>
Preserve the names of the specified class members (if they aren't removed in the shrinking step).
<keepclasseswithmembernames class_specification > class_member_specifications </keepclasseswithmembernames>
Preserve the names of the specified classes and class members, if all of the specified class members are present (after the shrinking step).
<whyareyoukeeping class_specification > class_member_specifications </whyareyoukeeping>
Print details on why the given classes and class members are being kept in the shrinking step.
<assumenosideeffects class_specification > class_member_specifications </assumenosideeffects>
Assume that the specified methods don't have any side effects, while optimizing. Only use this option if you know what you're doing!
<optimization name = "optimization_name" /> <optimizations filter = ""optimization_filter" />
Perform only the specified optimizations.
<keeppackagename name = "package_name" /> <keeppackagenames filter = "package_filter" />
Keep the specified package names from being obfuscated. If no name is given, all package names are preserved.
<keepattribute name = "attribute_name" /> <keepattributes filter = "attribute_filter" />
Preserve the specified optional Java bytecode attributes, with optional wildcards. If no name is given, all attributes are preserved.
<adaptclassstrings filter = "class_filter" />
Adapt string constants in the specified classes, based on the obfuscated names of any corresponding classes.
<adaptresourcefilenames filter
= "file_filter" />
Rename the specified resource files, based on the obfuscated names of the corresponding class files.
<adaptresourcefilecontents filter
= "file_filter" />
Update the contents of the specified resource files, based on the obfuscated names of the processed classes.
<dontnote filter
= "class_filter" />
Don't print notes about classes matching the specified class name filter.
<dontwarn filter
= "class_filter" />
Don't print warnings about classes matching the specified class name filter. Only use this option if you know what you're doing!
<configuration refid =
"ref_id" />
<configuration file =
"name" />
The first form includes the XML-style configuration specified in a <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.
Class path attributes and nested elements
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" The names of the jars (or aars, wars, ears, zips, apks, or directories), separated by the path separator.
location
= "name" (or file
= "name", or dir
= "name", or name
= "name") Alternatively, the name of a single jar (or aar, war, ear, zip, or directory).
refid
= "ref_id" Alternatively, a reference to the path or file set with the attribute id
= "ref_id". In addition, the jar elements can have ProGuard-style filter attributes:
filter
= "file_filter" An optional filter for all class file names and resource file names that are encountered.
apkfilter
= "file_filter" An optional filter for all apk names that are encountered.
jarfilter
= "file_filter" An optional filter for all jar names that are encountered.
aarfilter
= "file_filter" An optional filter for all aar names that are encountered.
warfilter
= "file_filter" An optional filter for all war names that are encountered.
earfilter
= "file_filter" An optional filter for all ear names that are encountered.
zipfilter
= "file_filter" An optional filter for all zip names that are encountered.
Keep modifier attributes
The keep tags can have the following modifier attributes:
includedescriptorclasses
= "boolean" (default = false) Specifies whether the classes of the fields and methods specified in the keep tag must be kept as well.
allowshrinking
= "boolean" (default = false) Specifies whether the entry points specified in the keep tag may be shrunk.
allowoptimization
= "boolean" (default = false) Specifies whether the entry points specified in the keep tag may be optimized.
allowobfuscation
= "boolean" (default = false) Specifies whether the entry points specified in the keep tag may be obfuscated.
Class specification attributes and nested elements
The keep tags can have the following class_specification attributes and class_member_specifications nested elements:
access
= "access_modifiers" The optional access modifiers of the class. Any space-separated list of "public", "final", and "abstract", with optional negators "!".
annotation
= "annotation_name" The optional fully qualified name of an annotation of the class, with optional wildcards.
type
= "type" The optional type of the class: one of "class", "interface", or "!interface".
name
= "class_name" The optional fully qualified name of the class, with optional wildcards.
extendsannotation
= "annotation_name" The optional fully qualified name of an annotation of the the class that the specified classes must extend, with optional wildcards.
extends
= "class_name" The optional fully qualified name of the class the specified classes must extend, with optional wildcards.
implements
= "class_name" The optional fully qualified name of the class the specified classes must implement, with optional wildcards.
<field
class_member_specification />
Specifies a field.
<method
class_member_specification />
Specifies a method.
<constructor
class_member_specification />
Specifies a constructor.
Class Member Specification Attributes
The class member tags can have the following class_member_specification attributes:
access
= "access_modifiers" The optional access modifiers of the class. Any space-separated list of "public", "protected", "private", "static", etc., with optional negators "!".
annotation
= "annotation_name" The optional fully qualified name of an annotation of the class member, with optional wildcards.
type
= "type" The optional fully qualified type of the class member, with optional wildcards. Not applicable for constructors, but required for methods for which the parameters
attribute is specified.
name
= "name" The optional name of the class member, with optional wildcards. Not applicable for constructors.
parameters
= "parameters" The optional comma-separated list of fully qualified method parameters, with optional wildcards. Not applicable for fields, but required for constructors, and for methods for which the type
attribute is specified.
Ant与Proguard集中的更多相关文章
- 利用Ant与Proguard混淆
利用Ant与Proguard混淆 摘自:https://blog.csdn.net/forlong401/article/details/22956711 2014年04月04日 20:20:21 f ...
- [Android]proguard重新编译和如何不混淆第三方jar包
转载自:http://glblong.blog.51cto.com/3058613/1536516 一.ant安装.环境变量配置及验证 (一)安装ant 到官方主页http://ant.apache. ...
- android ant 最简单的打包签名,混淆方法
使用ant打包,如果脚本都是我们自己一步一步来写的话,是一个比较麻烦的东西. 关于ant,我们详细看下: ant支持 ant debug,ant release等命令,我们需要签名混淆,那么就需要an ...
- 我的Android进阶之旅------>经典的大牛博客推荐(排名不分先后)!!
本文来自:http://blog.csdn.net/ouyang_peng/article/details/11358405 今天看到一篇文章,收藏了很多大牛的博客,在这里分享一下 谦虚的天下 柳志超 ...
- android自动打包方法(ant+proguard+签名)
前段时间做了一个android的网游项目,现在优化减少体积和防止别人反编译,需要把编译后.class进行混淆,开始在网上看了一些关于 ProGuard的介绍,基本上都是使用ADT自带的打包方式,那个打 ...
- ant+proguard签名打包 .jar
ant+proguard签名打包 .jar 摘自: https://blog.csdn.net/a_ycmbc/article/details/53432812 2016年12月02日 14:52:3 ...
- Eclipse与Android源码中ProGuard工具的使用
由于工作需要,这两天和同事在研究android下面的ProGuard工具的使用,通过查看android官网对该工具的介绍以及网络上其它相关资料,再加上自己的亲手实践,算是有了一个基本了解.下面将自己的 ...
- Ant搭建 一键生成APP技术 平台
1.博客概要 本文详细介绍了当今流行的一键生成APP技术.介绍了这种设计思想的来源,介绍了国内外的研究背景,并介绍了这个技术体系中的一些实现细节,欢迎各路大神们多提意见.一键生成技术,说的通俗点就是, ...
- 关于 ant 不同渠道自动打包的笔记
必要的java.android.ant文件及循环打包用到的ant的jar 下载Ant(这里的Ant不是eclipse和android SDk里面自带的ant) 官方下载地址:http://a ...
随机推荐
- Python问题之“NameError: name 'reload' is not defined”
出现这个错误的原因是你使用的Python版本已经不再使用了 在Python2.x中会用到reload来解决中文乱码问题 import sys reload(sys) sys.setdefaultenc ...
- delphi StringGrid 表格的复制粘贴
//参考如下代码--uses Clipbrd; function StringGridSelectText(mStringGrid: TStringGrid): string;var I, J: I ...
- 在AngularJS中使用谷歌地图把当前位置显示出来
如何使用谷歌地图把当前位置显示出来呢? --在html5中,为我们提供了navigator.geolocation.getCurrentPosition(f1, f2)函数,f1是定位成功调用的函数, ...
- AngularJS中使用$http对MongoLab数据表进行增删改查
本篇体验使用AngularJS中的$http对MongoLab数据表进行增删改查. 主页面: <button ng-click="loadCourse()">Load ...
- 枚举进程句柄File,Section,Mutant,Timer关闭Mutex句柄实现游戏多开
原文:http://www.cnblogs.com/Y4ng/archive/2012/09/06/EnumProcessHandle_EnumMutex.html 相信做过游戏多开的朋友就会发现,很 ...
- .Net Core邮件发送之MailKit
一 .在.Net Core中MailKit中提供了邮件的基础封装 它支持跨平台,并且支持 IMAP, POP3, SMTP 等协议 Nuget命令: Install-Package MailKit 官 ...
- Java中有哪些语法糖?
不要你写汇编,Java句句是糖 不能同意上面的这句话,要说为什么,首先要定义下面要讲的“语法糖”. 语法糖指计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,并没有给语言添加什么新东西,但是 ...
- 浅谈压缩感知(十九):MP、OMP与施密特正交化
关于MP.OMP的相关算法与收敛证明,可以参考:http://www.cnblogs.com/AndyJee/p/5047174.html,这里仅简单陈述算法流程及二者的不同之处. 主要内容: MP的 ...
- [Python设计模式] 第7章 找人帮忙追美眉——代理模式
github地址:https://github.com/cheesezh/python_design_patterns 题目1 Boy追求Girl,给Girl送鲜花,送巧克力,送洋娃娃. class ...
- grid - 网格线命名
通过grid-template-rows和grid-template-columns定义网格时,网格线可以被命名.网格线名称也可以设置网格项目位置. grid-template-rows和grid-t ...