使用Zipalign优化Android应用

本文介绍如何使用Android SDK中的ZipAlign工具优化应用性能。通过对资源文件进行4字节对齐,可提高读取效率,减少内存消耗。文章还列举了几种实现对齐的方法。
原文参考:Applications/android-sdk-mac_x86/docs/resources/articles/zipalign.html

android得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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值