Anybody who has developed mobile application using J2ME must already know that getting the smallest JAR file size is very important.
This is because the limit imposed by the mobile phone devices due to storage/memory limit on small devices. It is not unusual for you to get mobile devices with 32KB ,64KB or 256KB jar file limit.
This is where JAR file optimization is crucial for deploying your J2ME mobile application out in the wild. Here’s a few thing that you can do to reduce your JAR file size :
Optimise PNG files
PNG is a graphic format used primarily by J2ME devices, and is guaranteed to be cross-platform between mobile devices that implements J2ME.
The best part with PNG file is that its bitmap data is compressed using the deflate compression algorithm which can be easily optimised by easily obtainable tool :
Obfuscation does help in chopping unecessary code, renaming long variables and classes, thus making the class files smaller. Don’t forget to Obfuscate your package files before deployment.
It does not only protect your code, but it does save a lot of valueable space.
Proguard and RetroGuard is the most common obfuscator used in J2ME application
Recompress JAR files
Finally, after going through optimizing PNG files and obfuscating, you might want to try to recompress your JAR files using a tuned JAR compressor which favors size over speed. For this purpose, I prefer using KJar, a JAR file recompressor based on Ken Silverman’s KZIP.
This final step combined with previous optimisation will greatly reduces your JAR file, personally I’ve achieve 33% space saving by reducing my resulting JAR file size from 80KB to 53KB (27KB saving !)
Please visit SupremeJ2ME website for more information about optimising your J2ME application for size.