151

Android gradle produces apk in two binaries: unaligned and aligned.

The document said...

Once you have signed the APK with your private key, run zipalign on the file. This tool ensures that all uncompressed data starts with a particular byte alignment, relative to the start of the file. Ensuring alignment at 4-byte boundaries provides a performance optimization when installed on a device. When aligned, the Android system is able to read files with mmap(), even if they contain binary data with alignment restrictions, rather than copying all of the data from the package. The benefit is a reduction in the amount of RAM consumed by the running application.

Seems like aligned apk is strongly recommended to distribute. For me, I only use aligned apk as a result product and ignore unaligned apk.

Does unaligned apk have any special usage during development?

Youngjae
  • 24,352
  • 18
  • 113
  • 198

2 Answers2

198

It is a two step process. The unaligned apk is just an intermediate product.

  1. the unaligned apk is generated
  2. the unaligned gets aligned and produces the aligned apk
Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
flx
  • 14,146
  • 11
  • 55
  • 70
  • 3
    Thanks for the quick reply. So, we can say unaligned apk is just a interim thing? – Youngjae Feb 27 '14 at 03:13
  • 1
    Right. Some IDEs produce it as end product for the debug build to speed up the build process. – flx Feb 27 '14 at 03:16
  • 2
    does unalign apk file helps debug application ? Thanks :) – hqt Sep 14 '14 at 04:30
  • 11
    no it doesn't. it's basically the same content as the aligned zip file, only that file boundaries are not aligned to 4b blocks. – flx Sep 14 '14 at 09:24
49

The unaligned(signed) APK is needed because signing an aligned apk will undo the alignment.

From the docs:

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.

See this answer for more. Here is the detailed build process: enter image description here

SMR
  • 6,628
  • 2
  • 35
  • 56