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