Step 1: Check out the instructions at http://wiki.java.net/bin/view/Games/4KGamesDesign.
The file size of my optimized .class file is 12’354 bytes (compiled with eclipse, debug information included).
Step 2: Create a Zip file with your single .class file (mine is called bin.zip and it’s size is 7’361 Bytes).
Step 3: Compress the created File with proguard 4.2. The size of my .class file is now 9’411 bytes.
Step 4: Compress the optimized .jar file (mine is called bin.zip.proguard.jar) with JoGa.
Important: there is a Bug with JoGa, if you’re unable to run your .class File (Error: Exception in thread “main” java.lang.VerifyError: (class: N, method: <init> signature: ()V) Register 5 contains wrong type”) you need to deselect the option “Optimizations / byte code optimizations / optimize slot order”. After this optimize step, the size of the .class file is 7307 Bytes.
Step 5: Create a work directory and copy the Manifest.mf file and your compressed .class file inside it.
Step 6: Create a valid .jar file and compress it with BJWFlate.exe:
BJWFlate.exe -n -r -s 4192 -v NAMEIT.jar work\*
My .jar file is now 4’083 Bytes. You may re-run BJWFlate.exe with a different numsplits parameter if the .jar file is still too big.
Hint: You can also try the tool 4KJO, which does those task automatically. Unfortunately there are some bugs in this nice tool, so I couldn’t use it…
To save some bytes you can try to compile your java file as an older version:
javac -g:none -source 1.3 -target 1.3 N.java
The new proguard v4.3 works quite better than the older version, example:
cd `dirname $0`
java -jar ./proguard4.3beta3/lib/proguard.jar @default.xml
ls -al N*
Here are some settings from the default.xml file:
and my impressive dictionary for proguard looks like this:
Finally I compress the .class file with BJWFlate.exe – I use a wine cmd.exe shell to execute this little batch file:
BJWFlate.exe -a -y -n -r -s 128 -v ./out/n0128.jar work*
BJWFlate.exe -a -y -n -r -s 256 -v ./out/n0256.jar work*
BJWFlate.exe -a -y -n -r -s 512 -v ./out/n0512.jar work*
BJWFlate.exe -a -y -n -r -s 1024 -v ./out/n1024.jar work*
BJWFlate.exe -a -y -n -r -s 2048 -v ./out/n2048.jar work*
BJWFlate.exe -a -y -n -r -s 4096 -v ./out/n4096.jar work*
BJWFlate.exe -a -y -n -r -s 8192 -v ./out/n8192.jar work*