Optimizing for a smaller .cod (.jar) file

强颜欢笑 提交于 2019-12-07 07:47:51

问题


The RIM compiler performs extra optimization and compression on the resulting ".jar" while building the final .cod file, but there are things that can be done by the developer to significantly reduce the final .cod file size.

One such thing would be to run PNGCrush, OptiPNG, or a similar tool to reduce the size of the included .png files. In an application with a large number of image files (such as an app featuring a custom UI), this can yield a significant reduction in the final .cod file size.

Do you have any tips for optimizing the final .cod file for size? Something to be done in the .java code itself? Something to be done in the project structure? Something to be done to the files or resources?

Thanks!


回答1:


Good question!

  • Compression (GZip, ZLib) may be useful when installing large bin/txt/xml files

And that's what they say in RIM:

  • Setting appropriate access
  • Avoid creating interfaces
  • Use static inner classes
  • Avoid unnecessary field initialization
  • Import individual classes

Also, interesting facts:

All images was PNG format. I want to know why : compile with JDE 4.5 --> 900k, compile JDE 4.2, 2.6.1, 4.7 --> 1800k. What is difference ? Thanks !


Seems that JDE 4.5 uses more optimization techniques than older JDE versions.


Check the image below, it produced by PngOut from 55 K png image. It's size is 3427 bytes




回答2:


I think you most certainly want to consider a shrinker (and optimizer/obfusticator) like ProGuard (http://sourceforge.net/projects/proguard/). This can shrink your Java code by collapsing full class names into shortened versions, removing unused code, etc. Along the way it can improve the efficiency of the code. It's great. The only hard part is modifying your build to optimize the generated class files before the RIM build stuff gets its hands on it to make a .cod.




回答3:


A good approach is to GZIP all resources and then use net.rim.device.api.compress.GZIPInputStream class to load compressed files. That way you don't have to implement decompress code by yourself.

Also you can use pngout for optimizing image resources.




回答4:


Make sure that you use PNG-8 instead of PNG-24 when possible. Try to minimize number of colors in palette. After this, use PngOut.

As for ProGuard, I have problems on old BB devices when using optimize feachure of Progruard ("-dontoptimize" switch) - so use it carefully, although it is a great tool.



来源:https://stackoverflow.com/questions/1162217/optimizing-for-a-smaller-cod-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!