Jack is a new Android toolchain that compiles Java source into Android dex bytecode. It replaces the previous Android toolchain, which consists of multiple tools, such as javac, ProGuard, jarjar, and dx.
The Jack toolchain provides the following advantages:
Jack has its own .jack file format, which contains the pre-compiled dex code for the library, allowing for faster compilation (pre-dex).
The Jill tool translates the existing .jar libraries into the new library format, as shown below.
You don’t have to do anything differently to use Jack — just use your standard makefile commands to compile the tree or your project. Jack is the default Android build toolchain for M.
The first time Jack is used, it launches a local Jack compilation server on your computer:
The Jack server shuts itself down after an idle time without any compilation. It uses two TCP ports on the localhost interface, and so is not available externally. All these parameters (number of parallel compilations, timeout, ports number, etc) can be modified by editing the $HOME/.jack
file.
The $HOME/.jack
file contains settings for Jack server variables, in a full bash syntax.
Here are the available settings, with their definitions and default values:
SERVER=true
Enable the server feature of Jack.SERVER_PORT_SERVICE=8072
Set the TCP port number of the server for compilation purposes.SERVER_PORT_ADMIN=8073
Set the TCP port number of the server for admin purposes.SERVER_COUNT=1
Unused at present.SERVER_NB_COMPILE=4
Maximum number of parallel compilations allowed.SERVER_TIMEOUT=60
Number of idle seconds the server has to wait without any compilation before shutting itself down.SERVER_LOG=${SERVER_LOG:=$SERVER_DIR/jack-$SERVER_PORT_SERVICE.log}
File where server logs are written. By default, this variable can be overloaded by an environment variable.JACK_VM_COMMAND=${JACK_VM_COMMAND:=java}
The default command used to launch a JVM on the host. By default, this variable can be overloaded by environment variable.If your computer becomes unresponsive during compilation or if you experience Jack compilations failing on “Out of memory error”
You can improve the situation by reducing the number of Jack simultaneous compilations by editing your$HOME/.jack
and changing SERVER_NB_COMPILE
to a lower value.
If your compilations are failing on “Cannot launch background server”
The most likely cause is TCP ports are already used on your computer. Try to change it by editing your$HOME/.jack
(SERVER_PORT_SERVICE
and SERVER_PORT_ADMIN
variables).
If it doesn’t solve the problem, please report and attach your compilation log and the Jack server log (see ‘Finding the Jack log’ below to know where to find the server log file). To unblock the situation, disable jack compilation server by editing your $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
).
If your compilation gets stuck without any progress
Please report this and give us the following additional information (where possible):
jack-admin server-stat
.$HOME/.jack
file.jack-admin list-server
.kill -3
command to this server to dump its state into the log file.ls -lR $TMPDIR/jack-$USER.
ps j -U $USER.
You should be able to unblock yourself by killing the Jack background server (use jack-admin kill-server
), and then by removing its temporary directories contained in jack-$USER
of your temporary directory (/tmp
or $TMPDIR
).
If you have any other issues
To report bugs or request features, please use our public issue tracker, available at http://b.android.com, with theJack tool bug report or Jack tool feature request templates. Please attach the Jack log to the bug report.
Finding the Jack log
|
In case of reproducible Jack failures, you can get a more detailed log by setting one variable, as follows:
$ export ANDROID_JACK_EXTRA_ARGS="--verbose debug --sanity-checks on -D sched.runner=single-threaded"
Then use your standard makefile commands to compile the tree or your project and attach its standard output and error.
To remove detailed build logs use:
$ unset ANDROID_JACK_EXTRA_ARGS
Jack supports Java programming language 1.7 and integrates additional features described below.
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.
Currently, Jack does not reuse the library pre-dex if shrinking/obfuscation/repackaging is used in the compilation.
Incremental compilation means that only components that were 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 only a limited set of components.
Incremental compilation is deactivated when shrinking, obfuscation, repackaging or multi-dex legacy is enabled.
Currently incremental compilation is not enabled by default. To enable incremental builds, add the following line to the Android.mk file of the project that you want to build incrementally:
LOCAL_JACK_ENABLED := incremental
Note: The first time that you build your project with Jack if some dependencies are not built, use mma
to build them, and after that you can use the standard build command.
Jack has shrinking and obfuscation support and uses proguard configuration files to enable shrinking and obfuscation features. Here are the supported and ignored options:
Common options include the following:
@
-include
-basedirectory
-injars
-outjars // only 1 output jar supported
-libraryjars
-keep
-keepclassmembers
-keepclasseswithmembers
-keepnames
-keepclassmembernames
-keepclasseswithmembernames
-printseeds
Shrinking options include the following:
-dontshrink
Obfuscation options include the following:
-dontobfuscate
-printmapping
-applymapping
-obfuscationdictionary
-classobfuscationdictionary
-packageobfuscationdictionary
-useuniqueclassmembernames
-dontusemixedcaseclassnames
-keeppackagenames
-flattenpackagehierarchy
-repackageclasses
-keepattributes
-adaptclassstrings
Ignored options include the following:
-dontoptimize // Jack does not optimize
-dontpreverify // Jack does not preverify
-skipnonpubliclibraryclasses
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-keepdirectories
-target
-forceprocessing
-printusage
-whyareyoukeeping
-optimizations
-optimizationpasses
-assumenosideeffects
-allowaccessmodification
-mergeinterfacesaggressively
-overloadaggressively
-microedition
-verbose
-dontnote
-dontwarn
-ignorewarnings
-printconfiguration
-dump
Note: Other options will generate an error.
Jack uses jarjar configuration files to do the repackaging.
Note: Jack is compatible with "rule" rule types, but is not compatible with "zap" or "keep" rule types. If you need "zap" or "keep" rule types please file a feature request with a description of how you use the feature in your app.
Since dex files are limited to 65K methods, apps with over 65K methods must be split into multiple dex files. (See‘Building Apps with Over 65K Methods’ for more information about multidex.)
Jack offers native and legacy multidex support.