Needed tools:
proguard v4.2,
JoGa and
BJWFlate.exe.
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...
Continue reading "Optimize JAVA code for a 4k compo"
Posted by michu