Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 761
Khaled Saifullah Avatar asked May 21 '15 07:05

Khaled Saifullah


People also ask

What is the difference between debug apk and release apk?

Major differences are the debug apk and the release apk: For debug builds the apk will be signed with the default debug signing keys with debug flag enabled. For release apk you will have to explicitly specify the apk to sign with and the debug flag will be turned off so that it cannot be debugged.

Can I rename app-debug apk?

If anyone is looking to change apk name outside the Android studio(just to send this file to someone else, as in my case), just right click the app name and change it to whatever you want.

Can I install app-debug apk?

If you copy the app-debug. apk for output directory, the app will not be able to install. Reason: app-debug file will have all the debugging tools installed in that apk which are used for debugging in Android Studio, and you even notice that the app size is also high than the usual.

How do I debug an app from apk?

To start debugging an APK, click Profile or debug APK from the Android Studio Welcome screen. Or, if you already have a project open, click File > Profile or Debug APK from the menu bar. In the next dialog window, select the APK you want to import into Android Studio and click OK.


2 Answers

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.

like image 190
Bidhan Avatar answered Oct 12 '22 19:10

Bidhan


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.

like image 76
SMR Avatar answered Oct 12 '22 18:10

SMR