您的位置:首页 > 移动开发 > Android开发

使用Zipalign优化Android应用

2014-08-08 19:09 316 查看
原文参考:Applications/android-sdk-mac_x86/docs/resources/articles/zipalign.htmlandroid得SDK包含一个zipalign得工具,可以用来提升Android应用得性能。Google强烈推荐使用,本文描述了zipalign的用法及缘由。原文:In Android, data files stored in each application's apk are accessed by multiple
processes: the installer reads the manifest to handle the permissions associated with that application; the Home application reads resources to get the application's name and icon; the system server reads resources for a variety of reasons (e.g. to display
that application's notifications); and last but not least, the resource files are obviously used by the application itself.=============================================在Android种,apk的数据资源被多个进程访问,例如installer,home app,system server, app itself。原文:The
resource-handling code in Android can efficiently access resources when they're aligned on 4-byte boundaries by memory-mapping them. But for resources that are not aligned (that is, when
zipalign
hasn't been run on an apk), it has to fall back
to explicitly reading them — which is slower and consumes additional memory.=====================================================如果资源文件在内存映像种是4字节对齐的,则资源的读取会变得更为高效,但是一般来说,这些资源都没有这样对齐,因此读取的时候效率低下,因此应用会变慢,并且会消耗更多的内存。在开发过程中,不需要关注这个问题,android系统提供了相应的灵活控制。但是对终端用户会有严重的影响,最好的情况下:home app和未对齐应用会显的比较慢,最坏的情况下--android会由于内存压力杀掉应用进程。由于消耗了更多的内存,同时也会消耗更多的电量,应用有可能被用户卸载。对齐的方法很简单,下面分别列出:1、使用ADT。adt0.9.3以后,在导出签名版本的apk时,会自动做对齐。2、使用ANT。android sdk1.6版本之后,在debug模式下ant的build脚本会自动做对齐。在release模式下,build脚本会在应用签名后做对齐,因此需要在build文件种必须为
key.store
key.alias赋值。

3、手工对齐:
zipalign -v 4 source.apk destination.apk。

4、检查对齐:
zipalign -c -v 4 application.apk。
写的比较好的博客:http://kinggoo.com/zipalign.htm
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: