1page.title=zipalign 2@jd:body 3 4<p>zipalign is an archive alignment tool that provides important 5optimization to Android application (.apk) files. 6The purpose is to ensure that all uncompressed data starts 7with a particular alignment relative to the start of the file. Specifically, 8it causes all uncompressed data within the .apk, such as images or raw files, 9to be aligned on 4-byte boundaries. This 10allows all portions to be accessed directly with {@code mmap()} even if they 11contain binary data with alignment restrictions. 12The benefit is a reduction in the amount of RAM consumed 13when running the application.</p> 14 15<p>This tool should always be used to align your .apk file before 16distributing it to end-users. The Android build tools can handle 17this for you. When using Eclipse with the ADT plugin, the Export Wizard 18will automatically zipalign your .apk after it signs it with your private key. 19The build scripts used 20when compiling your application with Ant will also zipalign your .apk, 21as long as you have provided the path to your keystore and the key alias in 22your project {@code build.properties} file, so that the build tools 23can sign the package first.</p> 24 25<p class="caution"><strong>Caution:</strong> zipalign must only be performed 26<strong>after</strong> the .apk file has been signed with your private key. 27If you perform zipalign before signing, then the signing procedure will undo 28the alignment. Also, do not make alterations to the aligned package. 29Alterations to the archive, such as renaming or deleting entries, will 30potentially disrupt the alignment of the modified entry and all later 31entries. And any files added to an "aligned" archive will not be aligned.</p> 32 33<p>The adjustment is made by altering the size of 34the "extra" field in the zip Local File Header sections. Existing data 35in the "extra" fields may be altered by this process.</p> 36 37<p>For more information about how to use zipalign when building your 38application, please read <a href="{@docRoot}guide/publishing/app-signing.html">Signing 39Your Application</a>.</p> 40 41 42<h3>Usage</h3> 43 44<p>To align {@code infile.apk} and save it as {@code outfile.apk}:</p> 45 46<pre>zipalign [-f] [-v] <alignment> infile.apk outfile.apk</pre> 47 48<p>To confirm the alignment of {@code existing.apk}:</p> 49 50<pre>zipalign -c -v <alignment> existing.apk</pre> 51 52<p>The {@code <alignment>} is an integer that defines the byte-alignment boundaries. 53This must always be 4 (which provides 32-bit alignment) or else it effectively 54does nothing.</p> 55 56<p>Flags:</p> 57 58<ul> 59 <li>{@code -f} : overwrite existing outfile.zip</li> 60 <li>{@code -v} : verbose output</li> 61 <li>{@code -c} : confirm the alignment of the given file</li> 62</ul> 63 64 65 66