why unaligned apk is needed?

Youngjae picture Youngjae · Feb 27, 2014 · Viewed 59.6k times · Source

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?

Answer

flx picture flx · Feb 27, 2014

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