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,下面开始实例演示:

  1. 将 Android-SDK\tools 目录下的 zipalign.exe 文件拷贝到放置签名APK文件所在的目录(fileDir)
  2. 调用 cmd 窗口,在窗口中执行 cd /d fileDir,进入签名APK文件所在的目录
  3. 继续在 cmd 窗口中执行 zipalign -v 4 inFile.apk outFile.apk,看到窗口输出 Verification succesful 即完成了 APK 的优化(inFile.apk 为已经签名打包好的原始文件,outFile.apk 为优化完毕后的输出文件)

Android 编程下通过 zipalign 对 APK 文件进行优化的更多相关文章

  1. Android 自动编译、打包生成apk文件 3 - 使用SDK Ant方式

      相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式> &l ...

  2. Android 自动编译、打包生成apk文件 4 - 多渠道批量打包

    相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式 > < ...

  3. Android 自动编译、打包生成apk文件 2 - 使用原生Ant方式

    from://http://blog.csdn.net/androiddevelop/article/details/11100109 相关文章列表: <Android 自动编译.打包生成apk ...

  4. Android 编程下 App Install Location

    从 API 8 开始(参考官方文档:App Install Location | Android Developers),你可以将你的应用安装在外部储存中(例如,安装到设备的 SD 卡上).这是一个可 ...

  5. android 开发 程序中下载安装APK文件 问题汇总 解析程序包时出现问题

    1 若把APK文件保存到应用程序的files目录下,则一定注意保存时使用 FileOutputStream os = openFileOutput(fileName, MODE_WORLD_READA ...

  6. [Android]使用platform密钥来给apk文件签名的命令

    1.使用platform密钥对apk进行签名 1.1.进入<Android_Source_Path>/build/target/product/security,找到[platform.p ...

  7. Android 编程下 Canvas and Drawables

    Canvas and Drawables 安卓提供了一组绘制二维图形的 API(参考官方文档:Canvas and Drawables | Android Developers),这组 API 允许开 ...

  8. Android开发学习之反编译APK文件

    反编译的目的在于学习一些优秀的Android应用程序代码. 在进行反编译之前,需要准备好下面的软件工具(这些文件都放在同一文件下): 这些工具的下载地址:http://down.51cto.com/d ...

  9. Android 应用安装成功之后删除apk文件

    问题: 在应用开发中遇到需要这样的需求:在用户下载我们的应用安装之后删除安装包. 解决: android会在每个外界操作APK的动作之后发出系统级别的广播,过滤器名称: android.intent. ...

随机推荐

  1. [SQL Server]从 varchar 数据类型到 datetime 数据类型的转换产生一个超出范围的值。

    见下图sql, 使用dateadd()转换时报如题错误, 原因是数据库表中存入的数据格式不正确,  数据格式不正确,  数据格式不正确,  重要的事情讲3遍!! ca.batch_no的前8位必须是日 ...

  2. Agile Development敏捷软件开发之何为敏捷开发

    敏捷软件开发之何为敏捷开发 敏捷开发,Agile Development,就是指能够在需求迅速变化的情况下快速开发软件.我们接触最多敏捷实践方式有:极限编程(XP).结对编程.测试驱动开发(TDD)等 ...

  3. 【Oracle】Oracle约束的总结

    你对ORACLE约束的了解如何?比较模糊还是相当透彻?如果你对下面几个问题了如指掌的话,恭喜你,你已经对约束掌握得比较好了,不用看这篇文章了.ORACLE的约束有啥功能作用? 有哪些类型约束(不同版本 ...

  4. 【struts2】核心概念

    1)FilterDispatcher Struts2的前端控制器,也是Struts2的MVC中的控制器部分.在实际开发中,只需要在web.xml中配置一次即可,如下所示: <filter> ...

  5. Windbg+Procdump解决w3wp.exe CPU过百问题

    最近发布在windows  server2012  IIS8.0上的一个WebAPI项目,才几十个人在线,CPU就会出现过百情况,并且CPU一旦过百应用程序池就自动暂停掉,看到这个问题我感觉应该是程序 ...

  6. linux文件系统 - 初始化(一)

    术语表: struct task:进程 struct mnt_namespace:命名空间 struct mount:挂载点 struct vfsmount:挂载项 struct file:文件 st ...

  7. java中如何将byte[]里面的数据转换成16进制字符串

    原文链接: http://zhidao.baidu.com/link?url=RmLDjr4PtP_oUE5J2pKNZSvlHt1K7HcCh4-03Y7VkXYhJ0kawg01CtKHZc2uB ...

  8. youku视频

    获取视频信息: http://v.youku.com/player/getPlayList/VideoIDS/153548356 <div class="player" id ...

  9. ldconfig命令

    ldconfig是一个动态链接库管理命令 为了让动态链接库为系统所共享,还需运行动态链接库的管理命令--ldconfigldconfig 命令的用途,主要是在默认搜寻目录(/lib和/usr/lib) ...

  10. python dict 和 json 互转

    在Python语言中,json数据与dict字典以及对象之间的转化,是必不可少的操作. 在Python中自带json库.通过import json导入. import json 在json模块有2个方 ...