Difference between app-debug.apk and app-debug-unaligned.apk

AndroidAndroid StudioApk

Android Problem Overview


In android studio with build variant set to "debug" mode, I found two outputs of apk

  • app-debug.apk
  • app-debug-unaligned.apk

What is the differences between those files?

Android Solutions


Solution 1 - Android

The unaligned apk is just an intermediate apk. First, the unaligned apk is generated. Then, the unaligned apk gets aligned and produces the aligned apk which is the app-debug.apk. You can read more about it over here.

Solution 2 - Android

##Short Answer: app-debug-unaligned.apk = Unaligned Signed APK
app-debug.apk = Aligned Signed APK (RAM optimized using zipalign)


##Long Answer To understand the difference we need to know the following points: ###App signing process

  • generate a private key (keytool)
  • compile to get the unsigned APK -> unaligned unsigned APK
  • Sign app in debug/release mode using private key (jarsigner) -> unaligned signed APK
  • align the APK (zipalign) -> aligned signed APK

The entire signing process is explained here. ###Why do we need the intermediate app-debug-unaligned.apk at all? as per 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.

###What is the advantage? zipalign? The advantage is that aligned APKs are optimized for RAM usage so they will consume less RAM in the devices. From the docs:

> zipalign is an archive alignment tool that provides important > optimization to Android application (.apk) files. ....The benefit is a > reduction in the amount of RAM consumed when running the application.

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
QuestionKhaled SaifullahView Question on Stackoverflow
Solution 1 - AndroidBidhanView Answer on Stackoverflow
Solution 2 - AndroidSMRView Answer on Stackoverflow