Android 编程下通过 zipalign 对 APK 文件进行优化
zipalign
zipalign is an archive alignment tool that provides important optimization to Android application (.apk) files. The purpose is to ensure that all uncompressed data starts with a particular alignment relative to the start of the file. Specifically, it causes all uncompressed data within the .apk, such as images or raw files, to be aligned on 4-byte boundaries. This allows all portions to be accessed directly with mmap() even if they contain binary data with alignment restrictions. The benefit is a reduction in the amount of RAM consumed when running the application.
This tool should always be used to align your .apk file before distributing it to end-users. The Android build tools can handle this for you. When using Eclipse with the ADT plugin, the Export Wizard will automatically zipalign your .apk after it signs it with your private key. The build scripts used when compiling your application with Ant will also zipalign your .apk, as long as you have provided the path to your keystore and the key alias in your project ant.properties file, so that the build tools can sign the package first.
Caution: zipalign must only be performed after the .apk file has been signed with your private key. If you perform zipalign before signing, then the signing procedure will undo the alignment. Also, do not make alterations to the aligned package. Alterations to the archive, such as renaming or deleting entries, will potentially disrupt the alignment of the modified entry and all later entries. And any files added to an "aligned" archive will not be aligned.
The adjustment is made by altering the size of the "extra" field in the zip Local File Header sections. Existing data in the "extra" fields may be altered by this process.
For more information about how to use zipalign when building your application, please read Signing Your Applications.
Usage
To align infile.apk and save it as outfile.apk:
zipalign [-f] [-v] <alignment> infile.apk outfile.apk
To confirm the alignment of existing.apk:
zipalign -c -v <alignment> existing.apk
The <alignment> is an integer that defines the byte-alignment boundaries. This must always be 4 (which provides 32-bit alignment) or else it effectively does nothing.
Flags:
- -f : overwrite existing outfile.zip
- -v : verbose output
- -c : confirm the alignment of the given file
以上对 zipalign 的介绍和使用来自 Google Developer,下面开始实例演示:
- 将 Android-SDK\tools 目录下的 zipalign.exe 文件拷贝到放置签名APK文件所在的目录(fileDir)
- 调用 cmd 窗口,在窗口中执行 cd /d fileDir,进入签名APK文件所在的目录
- 继续在 cmd 窗口中执行 zipalign -v 4 inFile.apk outFile.apk,看到窗口输出 Verification succesful 即完成了 APK 的优化(inFile.apk 为已经签名打包好的原始文件,outFile.apk 为优化完毕后的输出文件)
Android 编程下通过 zipalign 对 APK 文件进行优化的更多相关文章
- Android 自动编译、打包生成apk文件 3 - 使用SDK Ant方式
相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式> &l ...
- Android 自动编译、打包生成apk文件 4 - 多渠道批量打包
相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式 > < ...
- Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式
from://http://blog.csdn.net/androiddevelop/article/details/11100109 相关文章列表: <Android 自动编译.打包生成apk ...
- Android 编程下 App Install Location
从 API 8 开始(参考官方文档:App Install Location | Android Developers),你可以将你的应用安装在外部储存中(例如,安装到设备的 SD 卡上).这是一个可 ...
- android 开发 程序中下载安装APK文件 问题汇总 解析程序包时出现问题
1 若把APK文件保存到应用程序的files目录下,则一定注意保存时使用 FileOutputStream os = openFileOutput(fileName, MODE_WORLD_READA ...
- [Android]使用platform密钥来给apk文件签名的命令
1.使用platform密钥对apk进行签名 1.1.进入<Android_Source_Path>/build/target/product/security,找到[platform.p ...
- Android 编程下 Canvas and Drawables
Canvas and Drawables 安卓提供了一组绘制二维图形的 API(参考官方文档:Canvas and Drawables | Android Developers),这组 API 允许开 ...
- Android开发学习之反编译APK文件
反编译的目的在于学习一些优秀的Android应用程序代码. 在进行反编译之前,需要准备好下面的软件工具(这些文件都放在同一文件下): 这些工具的下载地址:http://down.51cto.com/d ...
- Android 应用安装成功之后删除apk文件
问题: 在应用开发中遇到需要这样的需求:在用户下载我们的应用安装之后删除安装包. 解决: android会在每个外界操作APK的动作之后发出系统级别的广播,过滤器名称: android.intent. ...
随机推荐
- Utils--封装好的下载图片的方法
/** * 封装下载图片方法 * @param url 下载地址 * @param filename * @return 下载成功为true */ public boolean downfile(St ...
- java实现读取ftp服务器上的csv文件
定义ftp操作接口 import java.io.InputStream; import java.util.List; import org.apache.commons.net.ftp.FTPCl ...
- 整理打印PI值
准备锻炼背诵PI的小数,找到PI值: PI=3. 141592653589793238462643383279502884197169399375105820974944592307816406286 ...
- 【RS】CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Collaborative Filtering-CoupledCF:在推荐系统深度协作过滤中学习显式和隐式的用户物品耦合
[论文标题]CoupledCF: Learning Explicit and Implicit User-item Couplings in Recommendation for Deep Colla ...
- 推荐系统 BPR 算法求解过程
数据假设: 每个用户之间的偏好行为相互独立 同一用户对不同物品的偏序相互独立 则优化问题为极大化如下目标: [Reference] 1.论文翻译:BPR:面向隐偏好数据的贝叶斯个性化排序学习模型 2. ...
- Git的图形化工具使用教程
虽然感觉并没有什么暖用,但姑且还是写出来留作纪念好了 Git这种分布式版本控制系统最适合的就是单枪匹马搞开发的选手,不需要服务器,下载个git和图形工具,网速快十分钟就能搞定开始愉快的开发工作.我在搭 ...
- 【MySQL】MySQL解析用户权限管理
一.MySQL权限简介 关于mysql的权限简单的理解就是mysql允许你做你全力以内的事情,不可以越界.比如只允许你执行select操作,那么你就不能执行update操作.只允许你从某台机器上连接m ...
- mysql数据库优化 pt-query-digest使用
mysql数据库优化 pt-query-digest使用 一.pt-query-digest工具简介 pt-query-digest是用于分析 mysql慢查询的一个工具,它可以分析binlog.Ge ...
- Paros 网络抓包工具
1.Paros 简介 Paros 是一款数据抓包工具. 官网下载地址 Paros 其它下载地址 Paros v3.2.13 for Mac,密码:e4hk. 2.使用方法 2.1 打开 Paros 打 ...
- mysql 创建函数问题
ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declar ...