Shaving

In my quest for ever decreasing jar files I found one “simple” optimization which gave me a 10% decrease in file size!

I use antenna and proguard with my ant scripts. I use the wtkpackage task with preverify and obfuscation.

To make this optimization work, you need to give proguard two arguments:

<argument value="-defaultpackage ''"/>
<argument value="-overloadaggressively"/>

You will also need a -keep argument for the obfuscate task (previously done by the wtkpackage task)

<argument value="-keep public class my.package.MIDlet"/>

Unfortunatly you then have to use the wtkobfuscate task, since the wtkpackage doesn’t accept arguments. And by using the obfuscate task, you manually need to preverify it :confused:

So, do a wtkpackage without preverify and obfuscation. then obfuscate and finish off with a preverify.

One thing I’ve noticed - (and this may already be known to some/most here) - is that using local variables seems to decrease the size vs. using global variables. For instance, I have a program that contains two methods which use two global variables for temporary purposes. When I remove them and use two local pairs for the same purpose, my *.jar file shrunk by 20 bytes. In both instances, I use ProGuard to shrink the file, also, so I’m not sure of the savings beforehand (if any).

Hi,

    pls let me details about his, can we implement it to all J2ME application. my usual application will be J2ME Games

Regards
GR

I’m trying to use antenna and proguard and using wtkobfuscate and wtkpreverify in an attempt to package up my jars. But I’m having troubles with the preverification part:

JAR file creation failed with error -1
The preverified classes if any are in tmp41.

The preverify part of my ant script looks as follows:

Whatever I do, the ant build seems to fail on the above line with the “JAR file creation failed with error -1…”

Any tips would be much appreciated.

JAX’ing ontop of proguard is another incredibly quick and easy way to save another few Kb (~5%)

And - if you don’t have to pass T-mobiles utterly ridiculous acceptance criteria - you can 7zip/kzip the jar to save another 10-15%.

pack all your asset files to reduce the zips table of contents, another 1-2% saving.

Write your code with size in mind - no hardcoded array allocations - minimal member variables, structure your classes so JAX can eliminate & merge them.

Do agressive color reduction on your images (but leave your images in 8bpp)
Match the images palette to the color model used by the phone you are targeting.
pngout/pngcrush all your image assets to remove any ancillery png chunks

etc etc etc

The list is endless.

w00h000, my 1000th post :o :o :o

Mind you, I remember running into a couple of phones that didn’t like the 7zip-compressed jars and agressive obfuscation. A pair of Samsungs and an LG, but I can’t recall the specific models. If you use these methods and your game misteriously doesn’t work on a few phones, try without the added compression.

And while we’re on the topic:
A tool that automates a lot of the image compression.
A thread with some nice information on saving jar space, especially through image manipulations.

shmoove