当前位置: 首页 > 面试题库 >

Java:如何使用自定义Ant build.xml将ProGuard集成到Jar项目中

锺威
2023-03-14
问题内容

我有一个简单的Java项目,它引用了两(2)个库jar文件。想要集成ProGuard。

这是我当前的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>

问题答案:

我发现了几种集成方式,但这是最简单的方式。

<?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>

这是 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();
}


 类似资料:
  • 我正在构建我的第一个Android应用程序,我在github上发现了一个java项目,我想和我的应用程序集成在一起。我是否可以手动将java文件添加到我的android项目目录 app->java->com.example.appname java客户机的src->main目录有一个嵌套的文件结构,所以我不确定这是否会引起问题。 我已经尝试了本文中的解决方案,但我没有看到步骤2中提供的选项如何将现

  • 我已经创建了这个控制器 报告consultas.jrxml位于folded resources上 当我运行te应用程序并运行endpoint时,我会出现以下错误: 你能帮我吗?

  • 在处理arch4u-pmd项目期间,我们制定了几个基于java的pmd规则,在基于XML的规则集< code>our-rules.xml中配置它们,并将其作为普通的java库/工件(< code > io . github . ABC:my-PMD-rules:0 . 1 . 0 )发布到我们的工件存储库中。工件结构如下所示: 我们如何使用pmd插件将它们添加到Gradle项目中? 我们必须处理以

  • 我正在我的项目中使用Sikuli来处理一些flash按钮。当在本地运行脚本时,它工作得很好。问题是,当我需要运行build.gradle时,我需要在build.gradle中有Sikuli依赖项。我就是这么写的。运行构建时,会出现以下错误: > 错误:无法解析配置“:Compile”的所有依赖项。 找不到com.googlecode.javacpp:javacpp:0.1.要求::new_qa_a

  • 请容忍我,我不是编码专家。 我使用ANTRWorks 2在ANTLR4中构建了一个语法。我用各种测试字符串测试了语法,它在其中运行良好。现在我遇到的问题是在我自己的代码中使用生成的lexer和解析器。作为代码生成目标,我使用Java。 以下是我正在尝试的代码: 它的输出就是“查询”,这是我的起始规则。我希望类似AntlWorks的输出:“(查询(quant_expr query((match st

  • 我正在尝试将SpringBoot应用程序的一个服务用于另一个SpringBoot服务。由于一些限制,我不得不使用基于jar的方法,即,我使用命令maven build构建第一个项目,并使用为该项目创建的jar。 我将该jar添加到其他/依赖项目的构建路径中。但是我不能看到我的主要项目的服务。我也不能自动连接它们。几天前,不知何故,我能够看到服务,但是依赖项目的maven构建失败了,因为它无法在依赖