user2504879 user2504879 - 1 year ago 532
Android Question

Android Studio - How to ZipAlign apk

I have created a signed apk using Android Studio and I'm now going to zipalign it, I have read this:
but I'm still not sure where to add the lines of code, is it in the Gradle file and where in the file do I add the lines?

Answer Source

Inside you main module's build.gradle file you can have multiple build types along with your debug one.

You can specify zipAlign characterstic inside any of your buildType like

buildTypes {

     release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        zipAlignEnabled true

Note: Older versions use zipAlign, instead of zipAlignEnabled

Default gradle tasks always created for debug and release buildTypes whether you define or not. Debug is for debugging purpose and Release for Singed Application (Build > generate Signed Apk). You must define your signingConfig for release builds.

Check Build Types section in below mentioned link for other properties that you can use in your buildTypes