| Scott Main | 23110e4 | 2009-09-02 10:25:09 -0700 | [diff] [blame] | 1 | page.title=zipalign |
| 2 | @jd:body |
| 3 | |
| 4 | <p>zipalign is an archive alignment tool that provides important |
| 5 | optimization to Android application (.apk) files. |
| 6 | The purpose is to ensure that all uncompressed data starts |
| 7 | with a particular alignment relative to the start of the file. Specifically, |
| 8 | it causes all uncompressed data within the .apk, such as images or raw files, |
| 9 | to be aligned on 4-byte boundaries. This |
| 10 | allows all portions to be accessed directly with {@code mmap()} even if they |
| 11 | contain binary data with alignment restrictions. |
| 12 | The benefit is a reduction in the amount of RAM consumed |
| 13 | when running the application.</p> |
| 14 | |
| 15 | <p>This tool should always be used to align your .apk file before |
| 16 | distributing it to end-users. The Android build tools can handle |
| 17 | this for you. When using Eclipse with the ADT plugin, the Export Wizard |
| 18 | will automatically zipalign your .apk after it signs it with your private key. |
| 19 | The build scripts used |
| 20 | when compiling your application with Ant will also zipalign your .apk, |
| 21 | as long as you have provided the path to your keystore and the key alias in |
| 22 | your project {@code build.properties} file, so that the build tools |
| 23 | can 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. |
| 27 | If you perform zipalign before signing, then the signing procedure will undo |
| 28 | the alignment. Also, do not make alterations to the aligned package. |
| 29 | Alterations to the archive, such as renaming or deleting entries, will |
| 30 | potentially disrupt the alignment of the modified entry and all later |
| 31 | entries. 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 |
| 34 | the "extra" field in the zip Local File Header sections. Existing data |
| 35 | in the "extra" fields may be altered by this process.</p> |
| 36 | |
| 37 | <p>For more information about how to use zipalign when building your |
| 38 | application, please read <a href="{@docRoot}guide/publishing/app-signing.html">Signing |
| 39 | Your 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. |
| 53 | This must always be 4 (which provides 32-bit alignment) or else it effectively |
| 54 | does 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 | |