带dexguard的Java库

时间:2015-02-02 12:37:14

标签: java ant obfuscation dexguard

我想混淆我的纯Java库,但我不知道如何在my和build.xml文件中使用dexguard。有人能告诉我一个例子吗?我目前的代码如下:

<property file="build.properties"/> 

<taskdef resource="build.properties"
classpath="dexguard.jar" />

<target name="build">
    <antcall target="clean"/>
</target>   

<target name="clean">
    <delete dir="build"/>
    <antcall target="compile"/>
</target>

<target name="compile">
    <mkdir dir="build/classes"/>
    <javac srcdir="src" destdir="build/classes"/>
    <antcall target="jar"/>
</target>

<target name="jar" >
    <mkdir dir="build/jar"/>
    <jar destfile="build/jar/testlib.jar" basedir="build/classes">

    </jar>
    <antcall target="obfuscate"/>
</target>

<target name="obfuscate" 
description="Obfuscate compiled classes">
<dexguard>
      -libraryjars "dexguard.jar"
      -injars      build/jar/testlib.jar
      -outjars     build/jar/testlib_obf.jar
</dexguard>

<target name="run">
    <java jar="build/jar/testlib.jar" fork="true"/>
</target>

1 个答案:

答案 0 :(得分:0)

使用Gradle。

task obfDexguard(type: com.guardsquare.dexguard.gradle.DexGuardTask) {
    configuration 'dexguard.txt'

    injars  "build/jar/testlib.jar"
    outjars "build/jar/testlib_obf.jar"
}