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