针对较小的 .cod (.jar) 文件进行优化
RIM 编译器在构建最终 .cod 文件时对生成的“.jar”执行额外的优化和压缩,但开发人员可以采取一些措施来显着减小最终 .cod 文件的大小。
其中之一就是运行 PNGCrush, OptiPNG,或类似的工具来减小所包含的 .png 文件的大小。 在具有大量图像文件的应用程序(例如具有自定义 UI 的应用程序)中,这可以显着减小最终 .cod 文件的大小。
如何优化最终 .cod 文件的大小? .java 代码本身需要做什么? 项目结构中需要做什么? 要对文件或资源做些什么?
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.
How can I optimize 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好问题!
这就是 RIM 中所说的:
另外,有趣的事实:
Good question!
And that's what they say in RIM:
Also, interesting facts:
我认为你肯定想考虑像 ProGuard 这样的收缩器(和优化器/混淆器)(http://sourceforge. net/projects/proguard/)。 这可以通过将完整的类名压缩为缩短的版本、删除未使用的代码等来缩小 Java 代码。在此过程中,它可以提高代码的效率。 这很棒。 唯一困难的部分是在 RIM 构建工具使用它来制作 .cod 之前修改您的构建以优化生成的类文件。
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.
一个好的方法是对所有资源进行 GZIP,然后使用 net.rim.device.api.compress.GZIPInputStream 类加载压缩文件。 这样您就不必自己实现解压缩代码。
您还可以使用 pngout 来优化图像资源。
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.
确保尽可能使用 PNG-8 而不是 PNG-24。 尝试尽量减少调色板中的颜色数量。 之后,使用 PngOut。
至于 ProGuard,当我使用 Progruard 的优化功能(“-dontoptimize”开关)时,我在旧的 BB 设备上遇到了问题 - 所以请小心使用它,尽管它是一个很棒的工具。
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.