×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    13

    What can be done to decrease JAR size?

    Hi.

    As my project progresses it becomes more and more obvious that keeping the JAR size small enough is very difficult. I haven't done any special optimizing as this is the first time I really need to care about it.

    Could you tell me some optimizations that I should do first.

    I guess every class makes some overhead so putting the code in fewer classes reduces the JAR size? What about variables? I define "int i" for just about every for-loop that I use. Should I define only one "int i" and then use it in every for-loop?

    Thank you.

  2. #2
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Helsinki.FI
    Posts
    112

    RE: What can be done to decrease JAR size?

    Hello,

    two most significant ways to decrease JAR size are:

    1) Optimize your images. Fiddle with colors and such with your favourite image processing tool to get the PNGs into smallest possible size.

    2) Obfuscate your code. Obfuscator cuts the variable and method names wherever they are used. Obfuscation can result in as much as 30% size decrease.

    Kind reagrds,
    Tinke / FN
    DRINK COFFEE - Do stupid things faster with more energy

  3. #3
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    229

    RE: What can be done to decrease JAR size?

    I can second what Tinke says below. Experiment a bit with image tools for png compression. If you save a png from Adobe Photoshop that's say 10k, it'll probably load into Paintshop Pro and save out at 5k!

    Another thing that saves a lot of space it to concatonate all your resource files (images and others) into a single larger file. Put this in instead of lots of individual files and you'll save lots of space. This does increase runtime memory usage however since you need to load and process a larger file. It's a trade off between jar size and runtime memory usage, you have to choose which is important.

    Obfuscators I can recommend are Jax from IBM (www.alphaworks.ibm.com). This is expensive for a commercial license however, and not very well supported any more. JODE (jode.sourceforge.net) is also a good one, and is free software to boot.

    Hope this helps,

    Steve

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Irving, Texas, USA
    Posts
    419

    RE: What can be done to decrease JAR size?

    Hello,

    Other free obfuscators are:
    retroguard from www.retrologic.com
    proguard (check it from a search engine)

    Retroguard works directly with J2ME Wireless Toolkit 1.0.4.

    Regards,

    Petteri / Forum Nokia

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    13

    RE: What can be done to decrease JAR size?

    Thank you for your answers.

    I had already optimized my images so that thing was taken care of. But I didn't know anything about obfuscators. That was a pleasant surprise :-) I downloaded 1stBarrierMINI obfuscator and it gave me 17% decrease on JAR size by only a button click.

    Are there any big differences on how efficiently these obfuscators work? (still interested in decreasing the JAR size)

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    RE: What can be done to decrease JAR size?

    Hi,

    as already mentioned by the others you can:
    1. use obfuscation (I use retrologic on a big project and it saves me 20%)

    2. reduce the size of other resources that are packed into the jar-file (images, texts, ...)

    3. Then you can also fiddle in your java-code (refactor). For example remove all unnecessary methods-definitions like the many small getXYZ()/setXYZ-methods (use public object-attributes) and/or cluster the blockcontent of onetime-called sub-methods into the calling method (if this is the only one calling). Every unnessary method-definition usually creates around 100 bytes overhead in your class-file.

    4. If your code contains debugging/testing-relevant code-fragments then block them into a:
    if (debug) {
    ...
    }
    and define debug in your class in the following way:

    public static final boolean debug=false; // in the application version to be developed

    or

    public static final boolean debug=false; // in the application version to be shippend

    The compiler will automatically remove all "if (debug) {...}" code when debug==false.

    5. And last but not least see if it could reasonable be a solution to move the resources (images,text) outside of the jar-file, and then retrieve them from a server (runtime OTA)... (this might also make some telco's more happy due to some extra billable IP-trafic in the network ;-) )

  7. #7
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Switzerland
    Posts
    78

    RE: What can be done to decrease JAR size?

    For optimizing PNG files I will recommend the Image Optimizer found at http://www.xat.com/
    Here you can reduce the number of colors and see the result in real time. I have saved a good bit with this.

    Regarding Obfuscation.
    I combine the different systems, such as ProGuard, RetroGuard, JOPT (website was gone last time I checked).

    I made a batch file that runs through all combinations (ProGuard first, then RetroGuard next.. might give other result than RetroGuard and then ProGuard..)..

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    RE: What can be done to decrease JAR size?

    usefull batch png optimizer is Pngcrush (http://pmt.sourceforge.net/pngcrush/).

    it tries to repack image data with different algorithm parameters and can remove all chunks you don't need (text, phys, gama, etc)...

    lnx

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    13

    RE: What can be done to decrease JAR size?

    Thanks again for your great advises but now I'm having a trouble using my obfuscator. If I try to run a obfuscated JAR file in my phone or in an emulator I get an application error: Error verifying class mainClass.

    Do I need to do something after I have obfuscated a JAR file or is this error caused by the obfuscator that I use (1stBarrier MINI, http://www.jproof.com)?

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    19

    RE: What can be done to decrease JAR size?

    - ProGuard is working for sure
    - convert big pictures to jpg some of the nokia's phones
    support that format

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    RE: What can be done to decrease JAR size?

    dont forget to preverify after obfuscation!

  12. #12
    Registered User
    Join Date
    Mar 2003
    Posts
    36
    I use Jshrink to obfuscate my files. It gets them a little smaller than the other obfuscators I have used, and repacks the JAR file for you, updating the JAD file too! You can use it with Nokia UI Api.

    Available at: http://www.e-t.com/jshrink.html

    It costs to license, but they don't seem to mind if you keep applying for evaluation licenses.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •