Does zipalign execute automatically when a .apk is generated as signed from Android Studio?

2.1k views Asked by At

I am wondering if the method of generating a signed .apk for release , also zipaligns the apk . In the directions of the android page (http://developer.android.com/tools/publishing/app-signing.html#studio) , it is not clear if zipalign is a different step.

thank you!

2

There are 2 answers

4
Shivam Verma On BEST ANSWER

You can define build types in the build.gradle file.

buildTypes {

     debug {
        storeFile file("debug.keystore")
     }

     release {
        zipAlignEnabled true
     }
}

The debug config is used when you are debugging your apk and the release config when you're creating a release apk.

If you set zipAlignEnabled true in case of release, the apk will be zipaligned. If you do not specify it, the default value is true in case of release and the apk will be zipaligned automatically. For debug, the default value is false.

Read more about build types and other possible properties you can set here : http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types

0
Sam On

The Android build tools can handle this for you. Android Studio automatically aligns your APK.

use the below command to confirm the alignment of existing.apk:

zipalign -c -v <alignment> existing.apk

The is an integer that defines the byte-alignment boundaries. This must always be 4 (which provides 32-bit alignment) or else it effectively does nothing.

Flags:

-f : overwrite existing outfile.zip -v : verbose output -p : outfile.zip should use the same page alignment for all shared object files within infile.zip -c : confirm the alignment of the given file

Zipalign