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