Java的:如何在ProGuard的项目罐子使用自定义的Ant build.xml整合 [英] Java: How to integrate ProGuard in Jar Project using custom Ant build.xml

查看:170
本文介绍了Java的:如何在ProGuard的项目罐子使用自定义的Ant build.xml整合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是指两个(2)库jar文件简单的Java项目。要整合的ProGuard。

下面是我当前的build.xml:

 <?XML版本=1.0&GT?;
<,项目名称=样本默认为DISTBASEDIR =>
    <! - 生成JAR START - >
    <描述>样品库< /描述>
    <! - 设置全局属性此版本 - >
    <属性名=SRC位置=SRC/>
    <属性名=bin的位置=BIN/>    <目标名称=DIST>
        <罐子destfile =Samples.jarBASEDIR =斌/>
            <! - 使用**包括递归目录 - >
            <包括姓名=COM /样本/ **/>
        < /瓶>
    < /目标与GT;
< /项目>


解决方案

我发现了几种方法来整合它,但是这是做的最简单方法。

 <?XML版本=1.0&GT?;
<,项目名称=样本默认为DISTBASEDIR =>
    <! - 生成JAR START - >
    <描述>样品库< /描述>
    <! - 设置全局属性此版本 - >
    <属性名=SRC位置=SRC/>
    <属性名=bin的位置=BIN/>    <目标名称=DIST>
        <罐子destfile =Samples.jarBASEDIR =斌/>
            <! - 使用**包括递归目录 - >
            <包括姓名=COM /样本/ **/>
        < /瓶>
    < /目标与GT;
    <! - 生成JAR END - >    <! - 在local.properties文件被创建并通过Android的更新
         工具。
         它包含的路径的SDK。它应该*不*签入
         版本控制系统。 - >
    <物业档案=local.properties/>    <! - build.properties文件可以被创建和被从未接触过
         由机器人的工具。这是改变一些的地方
         默认的蚂蚁规则中使用的属性值。
         在这里,你可能需要更改/更新的一些属性:         source.dir
             源目录的名称。默认为SRC。
         out.dir
             输出目录的名称。默认值是'本'。         相关的SDK位置或项目目标应属性
         使用与更新行动Android的工具进行更新。         此文件是构建系统的一个组成部分的
         应用程序,并且签入到版本控制系统。          - >
    <物业档案=build.properties/>    <! - default.properties文件被创建,由Android的更新
         工具,以及ADT。
         此文件是构建系统的一个组成部分的
         应用程序,并且签入到版本控制系统。 - >
    <物业档案=default.properties/>    <! - 添加Proguard的任务 - >
    <属性名=proguard.jar位置=ProGuard的/ lib目录/ proguard.jar/>    <的taskdef资源=的ProGuard / ANT / task.properties
         CLASSPATH =$ {} proguard.jar/>
    < ProGuard的配置=proguard.cfg/>< /项目>

下面是在 proguard.cfg

  -injars Samples.jar
-outjars样品,out.jar
-libraryjars库/的android.jar
-printmapping out.map-renamesourcefileattribute的SourceFile
-keepattributes例外,InnerClasses,签名,德precated,
                的SourceFile,LineNumberTable,*注释*,EnclosingMethod-keep公共类* {
    公众保护*;
}-keepclassmembernames类* {
    java.lang.Class中的类$(java.lang.String中);
    java.lang.Class中的类$(java.lang.String中,布尔值);
}-keepclasseswithmembernames类* {
    天然的所述;方法&gt ;;
}-keepclassmembers枚举* {
    公共静态** []值();
    公共静态**的valueOf(java.lang.String中);
}-keepclassmembers类*实现java.io.Serializable {
    静态最后的serialVersionUID长;
    私有静态最终java.io.ObjectStreamField中的[] serialPersistentFields;
    私人无效的writeObject(java.io.ObjectOutputStream中);
    私人无效的readObject(java.io.ObjectInputStream中);
    java.lang.Object继承writeReplace();
    java.lang.Object中的readResolve();
}

I have simple java project which refers to two (2) library jar files. Want to integrate ProGuard.

Here's my current build.xml:

<?xml version="1.0" ?>
<project name="Samples" default="dist" basedir=".">
    <!-- generate JAR START -->
    <description>Samples Library</description>
    <!-- Setting global properties for this build -->
    <property name="src" location="src" />
    <property name="bin" location="bin" />

    <target name="dist">
        <jar destfile="Samples.jar" basedir="bin/">
            <!-- Use ** to include the directory recursively -->
            <include name="com/samples/**" />
        </jar>
    </target>
</project>

解决方案

I found several ways to integrate it but this is the simplest way to do it.

<?xml version="1.0" ?>
<project name="Samples" default="dist" basedir=".">
    <!-- generate JAR START -->
    <description>Samples Library</description>
    <!-- Setting global properties for this build -->
    <property name="src" location="src" />
    <property name="bin" location="bin" />

    <target name="dist">
        <jar destfile="Samples.jar" basedir="bin/">
            <!-- Use ** to include the directory recursively -->
            <include name="com/samples/**" />
        </jar>
    </target>
    <!-- generate JAR END -->

    <!-- The local.properties file is created and updated by the 'android'
         tool.
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" />

    <!-- The build.properties file can be created by you and is never touched
         by the 'android' tool. This is the place to change some of the
         default property values used by the Ant rules.
         Here are some properties you may want to change/update:

         source.dir
             The name of the source directory. Default is 'src'.
         out.dir
             The name of the output directory. Default is 'bin'.

         Properties related to the SDK location or the project target should
         be updated using the 'android' tool with the 'update' action.

         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems.

         -->
    <property file="build.properties" />

    <!-- The default.properties file is created and updated by the 'android'
         tool, as well as ADT.
         This file is an integral part of the build system for your
         application and should be checked into Version Control Systems. -->
    <property file="default.properties" />

    <!-- Add Proguard Tasks -->
    <property name="proguard.jar" location="proguard/lib/proguard.jar" />

    <taskdef resource="proguard/ant/task.properties"
         classpath="${proguard.jar}" />
    <proguard configuration="proguard.cfg"/>

</project>

Here's the proguard.cfg:

-injars       Samples.jar
-outjars      Samples-out.jar
-libraryjars  libs/android.jar
-printmapping out.map

-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
                SourceFile,LineNumberTable,*Annotation*,EnclosingMethod

-keep public class * {
    public protected *;
}

-keepclassmembernames class * {
    java.lang.Class class$(java.lang.String);
    java.lang.Class class$(java.lang.String, boolean);
}

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

这篇关于Java的:如何在ProGuard的项目罐子使用自定义的Ant build.xml整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆