如何使用ProGuard? [英] How do I use ProGuard?
问题描述
我在尝试学习如何使用 ProGuard ,它并没有我想象的那么容易。起初,我发现了一个简单的Java代码来试试,一个简单的两类Swing计算器< a>。
I was trying to learn how to use ProGuard, and it is no way as easy as I thought. At first I found a simple Java code to try it, a simple two class Swing calculator.
该代码可以通过跟随该链接找到,但我发现它太详细,在这里张贴它。无论如何,它是一个普通的应用程序,入口点在 Calc.main()
,没有包。
The code can be found by following that link, but I found it too verbose to post the it here. Anyway, it is a plain application with entry point on Calc.main()
, there are no packages.
然后我编译这两个源与:
Then I compiled both sources with:
$ javac *.java
并创建了 .jar
文件(因为看起来ProGuard只能使用jars):
and created the .jar
file (because it seems ProGuard only work with jars):
$ jar cvef Calc calc.jar *.class
added manifest
adding: Calc.class(in = 3869) (out= 2126)(deflated 45%)
adding: Calc$ClearListener.class(in = 468) (out= 327)(deflated 30%)
adding: CalcLogic.class(in = 1004) (out= 515)(deflated 48%)
adding: Calc$NumListener.class(in = 1005) (out= 598)(deflated 40%)
adding: Calc$OpListener.class(in = 1788) (out= 1005)(deflated 43%)
写了名为 obfuscate.pro
:
-injars calc.jar
-outjars calc_obf.jar
-libraryjars <java.home>/lib/rt.jar
-keep public class Calc extends javax.swing.JFrame {
public static void main(java.lang.String[]);
}
最后运行ProGuard:
And finally run ProGuard:
$ ~/progs/proguard/proguard4.8/bin/proguard.sh @obfuscate.pro
ProGuard, version 4.8
Reading program jar [/home/lucas/tmp/calc.jar]
Reading library jar [/usr/lib/jvm/java-7-openjdk-i386/jre/lib/rt.jar]
Error: The output jar is empty. Did you specify the proper '-keep' options?
好吧,显然没有用。我厌倦了使用ProGruard参数,特别是使用 -keep
选项,没有成功。所有我在与我的问题相关的文档中找到的无法帮助我。然后我求助你...有什么问题?如何做到?
Well, obviously didn't work. I got tired of messing with ProGruard parameters, specially with that -keep
options, with no success. All I found in the docs related to my problem could not help me. Then I am resorting to you... What is wrong? How to do it right?
推荐答案
我使用以下配置文件工作:
I got it to work using the following configuration file:
-injars calc.jar
-outjars calc_obf.jar
-libraryjars <java.home>/lib/rt.jar
-keep class Calc {
public static void main(java.lang.String[]);
}
最值得注意的是,我抛弃了 public
在前面类Calc
。
Most notably, I ditched the public
in front of class Calc
.
这篇关于如何使用ProGuard?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!