• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1page.title=Jack (Java Android Compiler Kit)
2@jd:body
3
4<!--
5    Copyright 2015 The Android Open Source Project
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18-->
19
20<div id="qv-wrapper">
21  <div id="qv">
22    <h2>In this document</h2>
23    <ol id="auto-toc">
24    </ol>
25  </div>
26</div>
27
28<h2 id=the_jack_toolchain>The Jack toolchain</h2>
29
30<p>Jack (Java Android Compiler Kit) is a new Android toolchain that compiles Java
31source into Android dex bytecode.  It replaces the previous Android toolchain,
32which consists of multiple tools, such as javac, ProGuard, jarjar, and dx.</p>
33
34<p>The Jack toolchain provides the following advantages:</p>
35
36<ul>
37  <li> <strong>Completely open source</strong><br>
38Available in AOSP; partners are welcome to contribute.
39  <li> <strong>Speeds compilation time</strong><br>
40
41Jack has specific supports to reduce compilation time: pre-dexing, incremental
42compilation and a Jack compilation server.
43  <li> <strong>Handles shrinking, obfuscation, repackaging and multidex</strong><br>
44Using a separate package such as ProGuard is no longer necessary.
45</ul>
46
47<img src="{@docRoot}images/jack-overview.png" height="75%" width="75%" alt="Jack overview" />
48<p class="img-caption"><strong>Figure 1. </strong>Jack (Java Android Compiler Kit)</p>
49
50<h2 id=the_jack_library_format>The .jack library format</h2>
51
52<p>Jack has its own .jack file format, which contains the pre-compiled dex code
53for the library, allowing for faster compilation (pre-dex).</p>
54
55<img src="{@docRoot}images/jack-library-file.png" height="75%" width="75%" alt="Jack library file contents" />
56<p class="img-caption"><strong>Figure 2. </strong>Jack library file contents</p>
57
58<h2 id=jack_intermediate_library_linker_jill>Jack Intermediate Library Linker (Jill)</h2>
59
60<p>The Jill tool translates the existing .jar libraries into the new library
61format, as shown below.</p>
62
63<img src="{@docRoot}images/jill.png" alt="Importing existing .jar libraries using Jill" />
64<p class="img-caption"><strong>Figure 3. </strong>Workflow to import an existing .jar library</p>
65
66<h2 id=using_jack_in_your_android_build>Using Jack in your Android build</h2>
67
68<p>You don’t have to do anything differently to use Jack — just use your standard
69makefile commands to compile the tree or your project.  Jack is the default
70Android build toolchain for M.</p>
71
72<p>The first time Jack is used, it launches a local Jack compilation server on
73your computer:</p>
74
75<ul>
76  <li> This server brings an intrinsic speedup, because it avoids launching a new host
77JRE JVM, loading Jack code, initializing Jack and warming up the JIT at each
78compilation. It also provides very good compilation times during small
79compilations (e.g. in incremental mode).
80  <li> The server is also a short-term solution to control the number of parallel Jack
81compilations, and so to avoid overloading your computer (memory or disk issue),
82because it limits the number of parallel compilations.
83</ul>
84
85<p>The Jack server shuts itself down after an idle time without any compilation.
86It uses two TCP ports on the localhost interface, and so is not available
87externally. All these parameters (number of parallel compilations, timeout,
88ports number, etc) can be modified by editing the<code> $HOME/.jack</code> file.</p>
89
90<h3 id=$home_jack_file>$HOME/.jack file</h3>
91
92<p>The <code>$HOME/.jack</code> file contains settings for Jack server variables, in a full bash syntax. </p>
93
94<p>Here are the available settings, with their definitions and default values:</p>
95
96<ul>
97  <li> <strong><code>SERVER=true</strong> </code>Enable the server feature of Jack.
98  <li> <strong><code>SERVER_PORT_SERVICE=8072</code>
99</strong>Set the TCP port number of the server for compilation purposes.
100  <li> <strong><code>SERVER_PORT_ADMIN=8073</code></strong>
101Set the TCP port number of the server for admin purposes.
102  <li> <strong><code>SERVER_COUNT=1</code></strong>
103Unused at present.
104  <li> <strong><code>SERVER_NB_COMPILE=4</code></strong>
105Maximum number of parallel compilations allowed.
106  <li> <strong><code>SERVER_TIMEOUT=60</code></strong>
107Number of idle seconds the server has to wait without any compilation before
108shutting itself down.
109  <li> <strong><code>SERVER_LOG=${SERVER_LOG:=$SERVER_DIR/jack-$SERVER_PORT_SERVICE.log}</code></strong>
110File where server logs are written. By default, this variable can be
111overloaded by an environment variable.
112  <li> <strong><code>JACK_VM_COMMAND=${JACK_VM_COMMAND:=java}</code></strong>
113The default command used to launch a JVM on the host. By default, this
114variable can be overloaded by environment variable.
115</ul>
116
117<h3 id=jack_troubleshooting>Jack troubleshooting</h3>
118
119<p><strong>If your computer becomes unresponsive during compilation or if you experience
120Jack compilations failing on “Out of memory error”</strong></p>
121
122<p>You can improve the situation by reducing the number of Jack simultaneous
123compilations by editing your<code> $HOME/.jack</code> and changing<code> SERVER_NB_COMPILE</code> to a lower value.</p>
124
125<p><strong>If your compilations are failing on “Cannot launch background server”</strong></p>
126
127<p>The most likely cause is TCP ports are already used on your computer. Try to
128change it by editing your <code>$HOME/.jack </code>(<code>SERVER_PORT_SERVICE</code> and <code>SERVER_PORT_ADMIN</code> variables).</p>
129
130<p>If it doesn’t solve the problem, please report and attach your compilation log
131and the Jack server log (see ‘Finding the Jack log’ below to know where to find
132the server log file). To unblock the situation, disable jack compilation server
133by editing your <code>$HOME/.jack</code> and changing <code>SERVER</code> to false. Unfortunately this will significantly slow down your compilation and
134may force you to launch <code>make -j</code> with load control (option "<code>-l</code>" of <code>make</code>). </p>
135
136<p><strong>If your compilation gets stuck without any progress</strong></p>
137
138<p>Please report this and give us the following  additional information (where
139possible):</p>
140
141<ul>
142  <li> The command line at which you are stuck.
143  <li> The output of this command line.
144  <li> The result of executing <code>jack-admin server-stat</code>.
145  <li> The <code>$HOME/.jack</code> file.
146  <li> The content of the server log with the server state dumped.  To get this —
147  <ul>
148    <li> Find the Jack background server process by running <code>jack-admin list-server</code>.
149    <li> Send a <code>kill -3</code> command to this server to dump its state into the log file.
150    <li> To locate the server log file, see ‘Finding the Jack log’ below.
151  </ul>
152  <li> The result of executing <code>ls -lR $TMPDIR/jack-$USER.</code>
153  <li> The result of running <code>ps j -U $USER.</code>
154</ul>
155
156<p>You should be able to unblock yourself by killing the Jack background server
157(use <code>jack-admin kill-server</code>), and then by removing its temporary directories contained in <code>jack-$USER</code> of your temporary directory (<code>/tmp</code> or <code>$TMPDIR</code>).</p>
158
159<p><strong>If you have any other issues </strong></p>
160
161<p>To report bugs or request features, please use our public issue tracker,
162available at <a href="http://b.android.com">http://b.android.com</a>,  with the <a href="https://code.google.com/p/android/issues/entry?template=Jack%20bug%20report">Jack tool bug report</a> or <a href="https://code.google.com/p/android/issues/entry?template=Jack%20feature%20request">Jack tool feature request</a> templates. Please attach the Jack log to the bug report. </p>
163<table>
164 <tr>
165    <td><strong>Finding the Jack log</strong>
166<ul>
167  <li> If you ran a make command with a dist target,  the Jack log is located at <code>$ANDROID_BUILD_TOP/out/dist/logs/jack-server.log</code>
168  <li> Otherwise you can find it in by running <code>jack-admin server-log</code>
169</ul>
170</td>
171 </tr>
172</table>
173
174<p>In case of reproducible Jack failures, you can get a more detailed log by
175setting one variable, as follows:</p>
176
177<pre class=prettyprint>
178$ export ANDROID_JACK_EXTRA_ARGS= "--verbose debug --sanity-checks on -D
179sched.runner=single-threaded"
180</pre>
181
182<p>Then use your standard makefile commands to compile the tree or your project
183and attach its standard output and error.</p>
184
185<p>To remove detailed build logs use:</p>
186
187<pre class=prettyprint>
188$ unset ANDROID_JACK_EXTRA_ARGS
189</pre>
190
191<h3 id=jack_limitations>Jack limitations</h3>
192
193<ul>
194  <li> The Jack server is mono-user by default, so can be only used by one user on a
195computer. If it is not the case, please, choose different port numbers for each
196user and adjust SERVER_NB_COMPILE accordingly. You can also disable the Jack
197server by setting SERVER=false in your $HOME/.jack.
198  <li> CTS compilation is slow due to current vm-tests-tf integration.
199  <li> Bytecode manipulation tools, like JaCoCo, are not supported.
200</ul>
201
202<h2 id=using_jack_features>Using Jack features</h2>
203
204<p>Jack supports Java programming language 1.7 and integrates additional features
205described below.</p>
206
207<h3 id=predexing>Predexing </h3>
208
209<p>When generating a JACK library file, the .dex of the library is generated and
210stored inside the .jack library file as a pre-dex.  When compiling, JACK reuses
211the pre-dex from each library.</p>
212
213<p>All libraries are pre-dexed.</p>
214
215<img src="{@docRoot}images/pre-dex.png" height="75%" width="75%" alt="Jack libraries with pre-dex" />
216<p class="img-caption"><strong>Figure 4. </strong>Jack libraries with pre-dex</p>
217
218<h4 id=limitations>Limitations</h4>
219
220
221<p>Currently, JACK does not reuse the library pre-dex if
222shrinking/obfuscation/repackaging is used in the compilation.</p>
223
224<h3 id=incremental_compilation>Incremental compilation</h3>
225
226
227<p>Incremental compilation means that only components that were touched since the
228last compilation, and their dependencies, are recompiled.  Incremental
229compilation can be significantly faster than a full compilation when changes
230are limited to only a limited set of components.</p>
231
232<h4 id=limitations>Limitations</h4>
233
234
235<p>Incremental compilation is deactivated when shrinking, obfuscation, repackaging
236or multi-dex legacy is enabled.</p>
237
238<h4 id=enabling_incremental_builds>Enabling incremental builds</h4>
239
240
241<p>Currently incremental compilation is not enabled by default.  To enable
242incremental builds, add the following line to the Android.mk file of the
243project that you want to build incrementally:</p>
244
245<pre class=prettyprint>
246LOCAL_JACK_ENABLED := incremental
247</pre>
248
249<p class="note"><strong>Note:</strong> The first time that you build your project with Jack if some dependencies
250are not built, use <code>mma</code> to build them, and after that you can use the standard build command.</p>
251
252<h3 id=shrinking_and_obfuscation>Shrinking and Obfuscation</h3>
253
254<p>JACK has shrinking and obfuscation support and uses proguard configuration
255files to enable shrinking and obfuscation features. Here are the supported and
256ignored options:</p>
257
258<h4 id=supported_common_options>Supported common options</h4>
259
260
261<p>Common options include the following:</p>
262
263<ul>
264  <li> <code>@</code>
265  <li> <code>-include</code>
266  <li> <code>-basedirectory</code>
267  <li> <code>-injars</code>
268  <li> <code>-outjars // only 1 output jar supported</code>
269  <li> <code>-libraryjars</code>
270  <li> <code>-keep</code>
271  <li> <code>-keepclassmembers</code>
272  <li> <code>-keepclasseswithmembers</code>
273  <li> <code>-keepnames</code>
274  <li> <code>-keepclassmembernames</code>
275  <li> <code>-keepclasseswithmembernames</code>
276  <li> <code>-printseeds</code>
277</ul>
278
279<h4 id=supported_shrinking_options>Supported shrinking options</h4>
280
281
282<p>Shrinking options include the following:</p>
283
284<ul>
285  <li> <code>-dontshrink</code>
286</ul>
287
288<h4 id=supported_obfuscation_options>Supported obfuscation options</h4>
289
290
291<p>Obfuscation options include the following:</p>
292
293<ul>
294  <li> <code>-dontobfuscate</code>
295  <li> <code>-printmapping</code>
296  <li> <code>-applymapping</code>
297  <li> <code>-obfuscationdictionary</code>
298  <li> <code>-classobfuscationdictionary</code>
299  <li> <code>-packageobfuscationdictionary</code>
300  <li> <code>-useuniqueclassmembernames</code>
301  <li> <code>-dontusemixedcaseclassnames</code>
302  <li> <code>-keeppackagenames</code>
303  <li> <code>-flattenpackagehierarchy</code>
304  <li> <code>-repackageclasses</code>
305  <li> <code>-keepattributes</code>
306  <li> <code>-adaptclassstrings</code>
307</ul>
308
309<h4 id=ignored_options>Ignored options</h4>
310
311
312<p>Ignored options include the following:</p>
313
314<ul>
315  <li> <code>-dontoptimize // Jack does not optimize</code>
316  <li> <code>-dontpreverify // Jack does not preverify</code>
317  <li> <code>-skipnonpubliclibraryclasses</code>
318  <li> <code>-dontskipnonpubliclibraryclasses</code>
319  <li> <code>-dontskipnonpubliclibraryclassmembers</code>
320  <li> <code>-keepdirectories</code>
321  <li> <code>-target</code>
322  <li> <code>-forceprocessing</code>
323  <li> <code>-printusage</code>
324  <li> <code>-whyareyoukeeping</code>
325  <li> <code>-optimizations</code>
326  <li> <code>-optimizationpasses</code>
327  <li> <code>-assumenosideeffects</code>
328  <li> <code>-allowaccessmodification</code>
329  <li> <code>-mergeinterfacesaggressively</code>
330  <li> <code>-overloadaggressively</code>
331  <li> <code>-microedition</code>
332  <li> <code>-verbose</code>
333  <li> <code>-dontnote</code>
334  <li> <code>-dontwarn</code>
335  <li> <code>-ignorewarnings</code>
336  <li> <code>-printconfiguration</code>
337  <li> <code>-dump</code>
338</ul>
339
340<p class="note"><strong>Note:</strong>  Other options will generate an error.</p>
341
342<h3 id=repackaging>Repackaging</h3>
343
344<p>JACK uses jarjar configuration files to do the repackaging.</p>
345
346<p class="note"><strong>Note:</strong> JACK is compatible with "rule" rule types, but is not compatible with "zap" or
347"keep" rule types. If you need "zap" or "keep" rule types please file a feature
348request with a description of how you use the feature in your app.</p>
349
350<h3 id=multidex_support>Multidex support</h3>
351
352
353<p>Since dex files are limited to 65K methods, apps with over 65K methods must be
354split into multiple dex files.  (See <a href="http://developer.android.com/tools/building/multidex.html">‘Building Apps with Over 65K Methods’</a> for more information about multidex.)</p>
355
356<p>Jack offers native  and legacy multidex support. </p>
357
358