1.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.

 google play不支持没用它的apk上线
 当系统启动一个应用时,如果它的apk是内存4字节对齐的,它可以直接通过mmap()函数访问资源和数据,比不对齐的快。zipalign 就是优化apk,让其按4字节对齐的工具。

  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. Android Studio automatically aligns your .apk after it signs it with your private key. The build scripts used when compiling your application with Gradle also align your .apk, as long as you have provided the path to your keystore and the key alias in your project gradle.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.

 本工具应该用在用私钥签名之后使用,否则无效。一但用zipalign优化后,就不要改变,否则会导致对齐失效。

  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.

 工具是通过修改zip文件的header section 中的extra属性来实现对齐的。

  For more information about how to use zipalign when building your application, please read Signing Your Application.

2.zipalign工具位置

  android-sdks/build-tools/xx  xx为版本号,每个目录下都有。

3.Usage 示例

  To align infile.apk and save it as outfile.apk:  对已存在的apk进行对齐优化。

 $zipalign [-f] [-v] <alignment> infile.apk outfile.apk

  To confirm the alignment of existing.apk:   对已经存在的apk进程对齐优化检测,验证。注意-c参数。

 $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.

 <alignment>通常值为4.

  Flags:

 zipalign 各参数的含义:
  • -f : overwrite existing outfile.zip
  • -v : verbose output
  • -c : confirm the alignment of the given file

如:

$~/Android/android-sdks/build-tools/23.0.2/zipalign -f -v 4 app-debug.apk app-zipaligned.apk
$~/Android/android-sdks/build-tools/23.0.2/zipalign -c -v 4 app-zipaligned.apk 

  在终端下输出如下:

 Verifying alignment of app-zipaligned.apk (4)...
53 AndroidManifest.xml (OK - compressed)
1388 res/drawable-hdpi-v11/__leak_canary_notification.png (OK)
2416 res/drawable-hdpi-v4/__leak_canary_icon.png (OK)
4744 res/drawable-hdpi-v4/__leak_canary_notification.png (OK)
5824 res/drawable-hdpi-v4/ab_overflow_btn.png (OK)
6136 res/drawable-hdpi-v4/corner_notice_new.png (OK)
7516 res/drawable-hdpi-v4/fast_scroll_preview_right.png (OK)
9488 res/drawable-hdpi-v4/fast_scroll_thumb_aje.png (OK)
9936 res/drawable-hdpi-v4/ic_launcher.png (OK)
13200 res/drawable-hdpi-v4/pgrsb.png (OK)
15132 res/drawable-hdpi-v4/refreshview_icon.png (OK)
15656 res/drawable-hdpi-v4/session_list_item_classes.png (OK)
25380 res/drawable-hdpi-v4/session_list_item_content_icon.png (OK)
26708 res/drawable-hdpi-v4/session_list_item_file_helper.png (OK)
27540 res/drawable-hdpi-v4/session_list_item_icon.png (OK)
28764 res/drawable-hdpi-v4/session_list_item_qq_news.png (OK)
31560 res/drawable-hdpi-v4/session_list_item_subscribe.png (OK)
32156 res/drawable-hdpi-v4/session_list_item_voice_notepad.png (OK)
33136 res/drawable-hdpi-v4/splash_bg.jpg (OK)
143168 res/drawable-hdpi-v4/tab_contaces_new_friend.png (OK)
144252 res/drawable-hdpi-v4/tab_contact_icon.png (OK)
145484 res/drawable-hdpi-v4/tab_contacts_cluster_chat.png (OK)
146800 res/drawable-hdpi-v4/tab_contacts_l.png (OK)
148096 res/drawable-hdpi-v4/tab_contacts_n.png (OK)
149944 res/drawable-hdpi-v4/tab_contacts_public_id.png (OK)
151240 res/drawable-hdpi-v4/tab_contacts_tags.png (OK)
152380 res/drawable-hdpi-v4/tab_discovery_fjr.png (OK)
153028 res/drawable-hdpi-v4/tab_discovery_gw.png (OK)
153680 res/drawable-hdpi-v4/tab_discovery_l.png (OK)
155392 res/drawable-hdpi-v4/tab_discovery_n.png (OK)
157728 res/drawable-hdpi-v4/tab_discovery_plp.png (OK)
158392 res/drawable-hdpi-v4/tab_discovery_pyq.png (OK)
159392 res/drawable-hdpi-v4/tab_discovery_sys.png (OK)
159932 res/drawable-hdpi-v4/tab_discovery_yx.png (OK)
160704 res/drawable-hdpi-v4/tab_discovery_yyy.png (OK)
161840 res/drawable-hdpi-v4/tab_personal_2wm.png (OK)
162100 res/drawable-hdpi-v4/tab_personal_bq.png (OK)
162868 res/drawable-hdpi-v4/tab_personal_l.png (OK)
163960 res/drawable-hdpi-v4/tab_personal_n.png (OK)
165668 res/drawable-hdpi-v4/tab_personal_qb.png (OK)
166124 res/drawable-hdpi-v4/tab_personal_sc.png (OK)
166896 res/drawable-hdpi-v4/tab_personal_sz.png (OK)
167724 res/drawable-hdpi-v4/tab_personal_xc.png (OK)
168164 res/drawable-hdpi-v4/tab_session_l.png (OK)
169524 res/drawable-hdpi-v4/tab_session_n.png (OK)
171604 res/drawable-hdpi-v4/tab_session_network_warning.png (OK)
172424 res/drawable-hdpi-v4/tab_session_qq_friend.png (OK)
174968 res/drawable-mdpi-v11/__leak_canary_notification.png (OK)
175728 res/drawable-mdpi-v4/__leak_canary_icon.png (OK)
177232 res/drawable-mdpi-v4/__leak_canary_notification.png (OK)
177716 res/drawable-mdpi-v4/ic_launcher.png (OK)
179700 res/drawable-xhdpi-v11/__leak_canary_notification.png (OK)
180952 res/drawable-xhdpi-v4/__leak_canary_icon.png (OK)
184060 res/drawable-xhdpi-v4/__leak_canary_notification.png (OK)
185460 res/drawable-xxhdpi-v11/__leak_canary_notification.png (OK)
187152 res/drawable-xxhdpi-v4/__leak_canary_icon.png (OK)
191840 res/drawable-xxhdpi-v4/__leak_canary_notification.png (OK)
193116 res/drawable-xxhdpi-v4/ic_launcher.png (OK)
198832 res/drawable-xxxhdpi-v11/__leak_canary_notification.png (OK)
200908 res/drawable-xxxhdpi-v4/__leak_canary_icon.png (OK)
207196 res/drawable-xxxhdpi-v4/__leak_canary_notification.png (OK)
208837 res/drawable/__leak_canary_toast_background.xml (OK - compressed)
209153 res/drawable/selector_dialog_bg.xml (OK - compressed)
209616 res/drawable/tab_contacts_state.xml (OK - compressed)
209947 res/drawable/tab_discovery_state.xml (OK - compressed)
210282 res/drawable/tab_personal_state_list.xml (OK - compressed)
210621 res/drawable/tab_session_list_item_layer.xml (OK - compressed)
210949 res/drawable/tab_session_state.xml (OK - compressed)
211283 res/layout/__leak_canary_display_leak.xml (OK - compressed)
211814 res/layout/__leak_canary_heap_dump_toast.xml (OK - compressed)
212314 res/layout/__leak_canary_leak_row.xml (OK - compressed)
212807 res/layout/__leak_canary_ref_row.xml (OK - compressed)
213383 res/layout/__leak_canary_ref_top_row.xml (OK - compressed)
213760 res/layout/aty_main.xml (OK - compressed)
214060 res/layout/aty_main_large.xml (OK - compressed)
214425 res/layout/aty_main_large_land.xml (OK - compressed)
214787 res/layout/aty_main_sw600dp.xml (OK - compressed)
215185 res/layout/aty_main_sw600dp_land.xml (OK - compressed)
215577 res/layout/aty_main_xlarge.xml (OK - compressed)
215965 res/layout/frgmt_main.xml (OK - compressed)
216517 res/layout/frgmt_splash.xml (OK - compressed)
216849 res/layout/tab_session_list_item.xml (OK - compressed)
217552 res/layout/tab_widget_layout.xml (OK - compressed)
217953 res/menu/main_menu.xml (OK - compressed)
218380 resources.arsc (OK)
238913 classes.dex (OK - compressed)
852364 pinyindb/pinyin_gwoyeu_mapping.xml (OK - compressed)
859683 pinyindb/pinyin_mapping.xml (OK - compressed)
865435 pinyindb/unicode_to_hanyu_pinyin.txt (OK - compressed)
959902 META-INF/MANIFEST.MF (OK - compressed)
962847 META-INF/CERT.SF (OK - compressed)
965810 META-INF/CERT.RSA (OK - compressed)
Verification succesful

Android 性能优化(27)*zipalign让apk数据对齐,运行更快。的更多相关文章

  1. Android性能优化系列之apk瘦身

    Android性能优化系列之布局优化 Android性能优化系列之内存优化 为什么APK要瘦身.APK越大,在下载安装过程中.他们耗费的流量会越多,安装等待时间也会越长:对于产品本身,意味着下载转化率 ...

  2. 【腾讯Bugly干货分享】Android性能优化典范——第6季

    本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/580d91208d80e49771f0a07c 导语 这里是Android性能优 ...

  3. android 性能优化

    本章介绍android高级开发中,对于性能方面的处理.主要包括电量,视图,内存三个性能方面的知识点. 1.视图性能 (1)Overdraw简介 Overdraw就是过度绘制,是指在一帧的时间内(16. ...

  4. 【转】Android性能优化之布局优化篇

     转自:http://blog.csdn.net/feiduclear_up/article/details/46670433 Android性能优化之布局优化篇 分类: andorid 开发2015 ...

  5. Android群英传笔记——第十章:Android性能优化

    Android群英传笔记--第十章:Android性能优化 随着Android应用增多,功能越来越复杂,布局也越来越丰富了,而这些也成为了阻碍一个应用流畅运行,因此,对复杂的功能进行性能优化是创造高质 ...

  6. Android 性能优化之工具和优化点总结

    Android性能优化学习 最近公司主抓性能优化工作,借此春风也学习到了许多Android性能优化方面的知识.由于组内队友的给力,优化的成果也是比较喜人.同时也学习和实践了不少知识,特此记录. 1.性 ...

  7. Android 性能优化之内存泄漏检测以及内存优化(中)

    https://blog.csdn.net/self_study/article/details/66969064 上篇博客我们写到了 Java/Android 内存的分配以及相关 GC 的详细分析, ...

  8. Android性能优化系列之App启动优化

    Android性能优化系列之布局优化 Android性能优化系列之内存优化 Android性能优化系列之apk瘦身 应用的启动速度缓慢是我们在开发过程中常常会遇到的问题,比方启动缓慢导致的黑屏.白屏问 ...

  9. Android性能优化:手把手带你全面了解 内存泄露 & 解决方案

    . 简介 即 ML (Memory Leak)指 程序在申请内存后,当该内存不需再使用 但 却无法被释放 & 归还给 程序的现象2. 对应用程序的影响 容易使得应用程序发生内存溢出,即 OOM ...

随机推荐

  1. Netbeans工具使用记录

     #自动换行设置 工具->选项->编辑器->格式设置

  2. Bzoj3060 [Poi2012]Tour de Byteotia

    3060: [Poi2012]Tour de Byteotia Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 251  Solved: 161 Des ...

  3. ehcache、memcache、redis三大缓存比较

    最近项目组有用到这三个缓存,去各自的官方看了下,觉得还真的各有千秋!今天特意归纳下各个缓存的优缺点,仅供参考!  Ehcache 在Java项目广泛的使用.它是一个开源的.设计于提高在数据从RDBMS ...

  4. SpringBoot使用logback自定义配置时遇到的坑 --- 在 /tmp目录下自动生成spring.log文件

    问题描述 SpringBoot项目使用logback自定义配置后,会在/tmp/ 目录下生成 spring.log的文件(如下图所示). 解决方案 通过各种资料的搜索,最终发现问题的所在(logbac ...

  5. 咏南 DELPHI DATASNAP LINUX中间件

    咏南 DATASNAP LINUX中间件   咏南 DATASNAP LINUX中间件,一套源码,同时支持WINDOWS和LINUX操作系统. 基于DELPHI 10.2 TOKYO开发 使用FIRE ...

  6. Java中Comparator接口和Comparable接口的使用

    普通情况下在实现对对象元素的数组或集合进行排序的时候会用到Comparator和Comparable接口,通过在元素所在的类中实现这两个接口中的一个.然后对数组或集合调用Arrays.sort或者Co ...

  7. 智能社区--HI3516C可视门禁研发出来咯

    铝壳.非常大气的外壳. 200W像素,HI3516C,携带server.创新的产品.欢迎交流:QQ237753582 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5u ...

  8. oracle initialization or shutdown in progress 问题解决

    今天登录oracle时遇到oracle initialization or shutdown in progress 这个错误提示,在网上搜了下,试了非常多方法,最后结合几种方法结合,成功攻克了问题! ...

  9. CLR-基元类型以及溢出检查 (CLR-Via-C#) 类型基础

    CLR-基元类型以及溢出检查   =========(CLR via C#阅读笔记)======== 基元类型(primitive type): 基元类型也不做过多的解释,举个例子即可清晰的辨别 在j ...

  10. 2015ACM/ICPC Asia Regional Changchun Online /HDU 5438 图

    Ponds                                   Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 1310 ...