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. ...
随机推荐
- Linux经常使用命令-权限管理命令-其它权限管理命令
命令名称:chown 英文: change file ownership 命令所在路径:/bin/chown 语法:chown [用户][文件或者文件夹] 功能描写叙述:改变文件或者文件夹的全部者 范 ...
- 使用 numpy.random.choice随机采样
使用 numpy.random.choice随机采样: 说明: numpy.random.choice(a, size=None, replace=True, p=None) 示例: >> ...
- Windows 7系统如何设置计划任务?
Windows 7系统如何设置计划任务? 问题描述:Windows 7系统如何设置计划任务? 任务计划概述:任务计划,可以将任何脚本.程序或文档安排在某个时间运行.“任务计划”在每次启动windows ...
- iOS block分析
block是代码块,其本质和变量类似.不同的是代码块存储的数据是一个函数体.使用Block,就可以像其他标准函数一样,传入参数,并得到返回值. 可以把Block当做Objective-C的匿名函数,B ...
- oracle收购Mysql后,Mysql的安装配置方法
自从Oracle收购MySQL后,略微发生了一些小小的变化,原来mysql安装完成后默认是没有密码的,但是新版的mysql安装完成后oracle提供了一个free password放着/root/.m ...
- sqlserver学习笔记(三)—— 为数据库添加新的用户
首先,用windows或sa身份登录sqlserver, 打开安全性——登录名——右键新建登录名:在选择页——常规中,新建命为user_b的登录名,选择sqlserver身份验证方式,设置密码确认密码 ...
- 【java】浅析java组件中的布局管理器
这篇博文笔者介绍一下java组件中,常用的布局管理器.java组件中的布局方式有好几十种,所有的这些布局管理器都实现了java.awt.LayoutManager接口.接下来笔者介绍一下常用的5种布局 ...
- NPM Node.js 包管理
1.NPM 简介 1.1 NPM Node.js® 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,可方便地构建快速,可扩展的网络应用程序的平台.Node.js 使用事件驱动, ...
- 还没被玩坏的robobrowser(6)——follow_link
背景 在做spider的时候,我们经常会有点击链接的需求. 考虑这样的一个简单spider:获取qq.com主页上的今日话题中的内容. 一般思路是先去qq.com首页上找到今日话题的链接,然后点击这个 ...
- python ipython spyder
ipython usage: ipython qtconsole --pylab inline anacond usage: 1. spyder 1. source ~/anacond/bin/act ...