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.
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
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%)
Wrote the ProGuard file named 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[]);
}
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?
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[]);
}
Most notably, I ditched the public
in front of class Calc
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With