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. ...
随机推荐
- android.telephony.SmsManager.sendMultipartTextMessage
smsManager.sendMultipartTextMessage(destAddress, null, divideContents, sentIntents, null); next step ...
- java中转义字符和路径符
来源于:http://blog.csdn.net/u011479200/article/details/69062343 在Java的实际开发中,经常会遇填写一个文件的相对路径或者是绝对路径的问题,对 ...
- JAVA删除文件及文件夹
JAVA在删除文件或文件夹时,在java.io.File类下有个delete的方法,并且可以返回true or false, 用这个方法来删除单个文件时,很好使,但在删除文件夹时,如果文件夹下面有文件 ...
- Jquery对input file控件的onchange事件只生效一次的解决方案
1.原始方法:把事件写在file控件的onchange=""里面: 2.Jquery方法一: $('#fileId').live('change',function(){ //逻辑 ...
- mysql慢查询日志相关参数
-- mysql慢查询日志相关参数 -- 慢查询日志时间 show variables like "long_query_time"; -- 将时间设置为2s ; -- 是否开启慢 ...
- TortoiseSVN 命令 (命令行执行工具)
TortoiseSVN是一个GUI客户端,这个自动化指导为你展示了让TortoiseSVN对话框显示并收集客户输入,如果你希望编写不需要输入的脚本,你应该使用官方的Subversion命令行客户端. ...
- 跟我学SharePoint 2013视频培训课程——什么是SharePoint 2013(1)
课程简介 第一天,介绍什么是SharePoint 2013. 视频 SharePoint 2013 交流群 41032413
- linux 免输入密码脚本
#! /usr/bin/expectset command [lindex $argv 0]set passwd [lindex $argv 1]spawn su - root -c $command ...
- 【转载】使用 Google Guava 美化你的 Java 代码
转载地址: https://blog.csdn.net/wisgood/article/details/13297535 原文地址:https://my.oschina.net/leejun2005/ ...
- URL中#号的含义
一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如, http://www.example.com/index.html#print 就代表网页index.html的prin ...