why unaligned apk is needed?

AndroidApkRelease

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYoungjaeView Question on Stackoverflow
Solution 1 - AndroidflxView Answer on Stackoverflow
Solution 2 - AndroidSMRView Answer on Stackoverflow