Proguard是个优秀的java混淆工具,使用示例如下,一个java工程对外接口代码如下(无需混淆)
package com.ciaos.open; import com.ciaos.inner.InnerTool; public class OpenTool { public static void method() { System.out.println("public method"); InnerTool.method(); } }
内部调用函数如下(需要混淆)
package com.ciaos.inner; public class InnerTool { public static void method() { System.out.println("need encrypt"); } }
我们只想在打包的jar文件中保留OpenTool.method接口,则proguard配置文件library.pro文件如下:
# # This ProGuard configuration file illustrates how to process a program # library, such that it remains usable as a library. # Usage: # java -jar proguard.jar @library.pro # # Specify the input jars, output jars, and library jars. # In this case, the input jar is the program library that we want to process. -injars D:libtool.jar -outjars D:libtool_min.jar -libraryjars C:UsersshipengAppDataLocalMyEclipse Professional 2014inarycom.sun.java.jdk7.win32.x86_1.7.0.u45jrelib t.jar #-libraryjars E:Worksfastjson-1.1.34.android.jar -printmapping mapproguard.map -overloadaggressively -defaultpackage '' -allowaccessmodification -dontoptimize -overloadaggressively -keepattributes InnerClasses,SourceFile,LineNumberTable,Signature -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -optimizationpasses 5 -keepattributes Exceptions -keep public class com.ciaos.open.OpenTool { public *; } #-keep public class com.ciaos.inner.InnerTool #{ #public *; #}
混淆工具脚本
del "D:libtool_min.jar"
java -jar lib/proguard.jar @library.pro
pause
更多用法参照Proguard官网,proguard也有插件集成到eclipse中。