Shrinking the size of your Java MIDlets
As you add more code and graphics to a MIDlet suite the resulting size of the MIDlet jar will increase. The HyConExplorer/J2ME MIDlet suite reached last week a size of ~260KB. PNG graphics was over a 100KB alone. So I decided to try to shrink the size of the jar-archive.
All of the PNG graphics in the project were created (mainly based on Jimmac’s Gnome icons) in Adobe PhotoShop. There were about 30 files with an overall size of over 100KB. To decrease the size of the files I tried a program called Pngcrush. Pngcrush is a small command-line tool based around GNU’s libpng and zlib. Running Pngcrush on the files reduced the size to 52KB—about half the size of the PhotoShop versions (and the size reduction is of course completely lossless wrt. the image data).
After this success it was time to reduce the size of the Java Class files. I had tried Proguard before as it is integrated into EcplipseME, but had not have much luck with resulting files. There seemed to be missing some classes in the Jar after the Obfucating process. However, I had missed one important command line option to Proguard:
-dontusemixedcaseclassnames
If Proguard is used on a platform with a case insensitive file system this option must be used otherwise the generated class files will override each other (e.g. class ‘x’ will override class ‘X’).
After this small discovery Proguard worked like a charm, and the final jar produced with tools was only ~130KB. So with out changing a single line of code I reduced the size of the package to about half the size of the original jar archive… Great tools!
Comments(0)