Jack is an Android toolchain that compiles Java source into Android dex bytecode. It replaces the previous Android toolchain that consisted of multiple tools such as javac, ProGuard, jarjar, and dx. As Jack is the default Android build toolchain for Android 6.x, you don’t have to do anything differently to use Jack—just use your standard makefile commands to compile the tree or your project.

About Jack

The Jack toolchain provides the following advantages:

Jack overview
Figure 1. Jack overview.

As of Android 7.0, Jack supports code coverage with JaCoCo. For details, refer to Code Coverage with JaCoCo and Java 8 Language Features.

Jack library format

Jack has its own .jack file format that contains the pre-compiled dex code for the library, allowing for faster compilation (pre-dex).

Jack library file contents
Figure 2. Jack library file contents.

Jill

The Jill tool translates the existing .jar libraries into the new library format, as shown below.

Importing .jar libraries with Jill
Figure 3. Workflow to import an existing .jar library.

Jack compilation server

The first time Jack is used, it launches a local Jack compilation server on your computer. This server:

The Jack server shuts itself down after an idle time without any compilation. It uses two TCP ports on the localhost interface and is not available externally. All parameters (number of parallel compilations, timeout, ports number, etc.) can be modified by editing the $HOME/.jack file.

$HOME/.jack file

The $HOME/.jack file contains the following settings for Jack server variables in a full bash syntax:

Troubleshooting Jack compilations

Problem Action
Your computer becomes unresponsive during compilation or you experience Jack compilations failing on “Out of memory error” You can improve the situation by reducing the number of simultaneous Jack compilations by editing $HOME/.jack and changing SERVER_NB_COMPILE to a lower value.
Compilations are failing on “Cannot launch background server” The most likely cause is TCP ports are already used on your computer. Change ports by editing $HOME/.jack (SERVER_PORT_SERVICE and SERVER_PORT_ADMIN variables).

If it doesn’t solve the problem, report the error (be sure to attach your compilation log and the Jack server log). To unblock the situation, disable the Jack compilation server by editing $HOME/.jack and changing SERVER to false. Unfortunately this will significantly slow down your compilation and may force you to launch make -j with load control (option -l of make).
Compilation gets stuck without any progress Report and provide the following information when possible:
  • Command line at which you are stuck.
  • Output of this command line.
  • Result of executing jack-admin server-stat.
  • $HOME/.jack file.
  • Content of the Jack server log with the server state dumped. To get the server log:
    • Find the Jack background server process by running jack-admin list-server.
    • Send a kill -3 command to this server to dump its state into the log file.
  • Result of executing ls -lR $TMPDIR/jack-$USER.
  • Result of running ps j -U $USER.
To unblock the situation, kill the Jack background server using jack-admin kill-server) then remove the temporary directories contained in jack-$USER of your temporary directory (/tmp or $TMPDIR).
Other issues To report bugs or request features, use the public issue tracker at http://b.android.com. Use the Jack tool bug report or Jack tool feature request templates and remember to attach the Jack log to the bug report.

Finding the Jack log

If you ran a make command with a dist target, the Jack log is located at $ANDROID_BUILD_TOP/out/dist/logs/jack-server.log. Otherwise, you can find the log by running jack-admin server-log. In case of reproducible Jack failures, you can get a more detailed log by setting the following variable:

export ANDROID_JACK_EXTRA_ARGS="--verbose debug --sanity-checks on -D sched.runner=single-threaded"

Use standard makefile commands to compile the tree (or your project) and attach standard output and error. To remove detailed build logs, run:

unset ANDROID_JACK_EXTRA_ARGS

Jack limitations

Using Jack

Jack supports Java programming language 1.7 and integrates the additional features described below.

Predexing

When generating a Jack library file, the .dex of the library is generated and stored inside the .jack library file as a pre-dex. When compiling, Jack reuses the pre-dex from each library. All libraries are pre-dexed:

Jack libraries with pre-dex
Figure 4. Jack libraries with pre-dex.

Jack does not reuse the library pre-dex if shrinking, obfuscation, or repackaging is used in the compilation.

Incremental compilation

Incremental compilation means that only the components touched since the last compilation (and their dependencies) are recompiled. Incremental compilation can be significantly faster than a full compilation when changes are limited to a set of components.

Incremental compilation is not enabled by default (and is automatically deactivated when shrinking, obfuscation, repackaging or multi-dex legacy is enabled). To enable incremental builds, add the following line to the Android.mk file of the project you want to build incrementally:

LOCAL_JACK_ENABLED := incremental

Shrinking and obfuscation

Jack uses proguard configuration files to enable shrinking and obfuscation.

Common options include the following:

Shrinking options include the following:

Obfuscation options include the following:

Ignored options include the following:

Repackaging

Jack uses jarjar configuration files to do repackaging. While Jack is compatible with "rule" rule types, it is not compatible with "zap" or "keep" rule types. If you need "zap" or "keep" rule types, file a feature request with a description of how you use the feature in your app.

Multidex support

Jack offers native and legacy multidex support. Since dex files are limited to 65K methods, apps with over 65K methods must be split into multiple dex files. For more details, refer to Building Apps with Over 65K Methods.