Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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: http://developer.android.com/tools/help/zipalign.html 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?

like image 762
jtmwanakhu Avatar asked Jan 20 '14 19:01

jtmwanakhu


People also ask

How does Zipalign work on Android?

zipalign is a zip archive alignment tool. It ensures that all uncompressed files in the archive are aligned relative to the start of the file. This allows those files to be accessed directly via mmap(2) , removing the need to copy this data in RAM and reducing your app's memory usage.

Do I need to Zipalign AAB?

For AAB files, there is no official guide to zipalign, so it is not required.

Where can I find Zipalign?

Zipalign Command (Step-By-Step) Navigate to your program files directory and open up android-sdk> build-tools > the build-tools version you have (27.0. 3 for me). At the bottom of that folder you should see your zipalign file.


1 Answers

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

You can specify zipAlign characteristic inside any of your buildType by using

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 Signed 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

http://tools.android.com/tech-docs/new-build-system/user-guide

like image 136
Piyush Agarwal Avatar answered Oct 11 '22 07:10

Piyush Agarwal