Skip to content

Latest commit

 

History

History
49 lines (37 loc) · 2.57 KB

Zipalign优化.md

File metadata and controls

49 lines (37 loc) · 2.57 KB

Zipalign优化

Zipalign优化工具是SDK中自带的优化工具,在android-sdk-windows\build-tools\23.0.1,在我们上传Google Pay的时候都会遇到您上传的Apk没有经过Zipalign处理 的失败提示,就是说如果你的apk没有使用zipalign优化,那google play是拒绝给你上架的,从这里能看出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.
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.

大意就是它提供了一个灰常重要滴功能来确保所有未压缩的数据都从文件的开始位置以指定的4字节对齐方式排列,例如图片或者 raw文件。当然好处也是大大的,就是能够减少内存的资源消耗。最后他还特意提醒了你一下就是一定在对apk签完名之后再用zipalign 优化,如果你在之前用,那无效。

废多看用法:

  • 首先我要检查下我的apk到底用没用过zipalign优化呢?
    zipalign -c -v 4 test.apk
    这个4是神马呢?就是4个字节的队列方式
    命令一顿执行,然后打出来了Verification failed,我不想再解释了。

  • 如何使用?
    zipalign -f -v 4 test.apk zip.apk
    就是把当前的test.apk使用zipalign优化,优化完成后的是zip.apk

Flag:

  • -f : overwrite existing outfile.zip
  • -v : verbose output
  • -c : confirm the alignment of the given file