Jack & Jill : Android Tool Chain
Introduction of "Jack & Jill" Jack & Jill are the new compilers for the Android developers is brought by Google. This is an experimental Andorid tool chain including a compiler from Java source code to the Android dex file format. Jack has its own .jack file format which ...
Introduction of "Jack & Jill"
Jack & Jill are the new compilers for the Android developers is brought by Google. This is an experimental Andorid tool chain including a compiler from Java source code to the Android dex file format. Jack has its own .jack file format which contains the pre-compiled dex code for the library to allow faster compilation (pre-dex). There is also a tool that translates existing .jar files to the .jack library format called Jill.
Jack (Java Android Compiler Kit) : Jack compiles Java source into Android dex bytecode. It replaces the previous Android toolchain which consists of multiple tools such as javac, ProGuard, jar, and dx. The Jack toolchain provides the following advantages:
- It's avaliable in AOSP(Android Open Source Project).
- Jack has specific supports to reduce compilation time: pre-dexing, incremental compilation and a Jack compilation server.
- It handles shrinking, obfuscation, repackaging and multidex. By using Jack, Android developers can avoid separate package such as ProGuard.
There is a predexing concept of .jack files from java source codes on the above picture.
Jack Intermediate Library Linker (Jill) : It helps to create the intermediate byte code .jayce to translate the existing .jar libraries into the new library format.
Work Flow
When the new tool chain is enabled, Jill will translate any libraries you are referencing to a new Jack library file (.jack). This prepares them to be quickly merged with other .jack files. The Android Gradle plugin and Jack collect any .jack library files, along with your source code, and compiles them into a set of dex files. During the process, Jack also handles any requested code minification. The output is then assembled into an APK file as normal.
Usage in Android Studio
Jack & Jill are available for sdk 21.1.1+ as well as Android 1.0.0+ Gradle plugin. To use it, firstly ensure the required sdk version & gradle plugin then add a single line in your build.gradle file as following.
android { buildToolsRevision '21.1.1' defaultConfig { // Enable the experimental Jack build tools. useJack = true } }
After adding the line perform a build of your application to produce a new APK. If you want to build your app with both toolchains then you can follow the recommended product flavors. The gradle snap will be like below.
android { productFlavors { dev { ... } experimental { useJack = true } prod { ... } } }
Benefit
The primary goal is to combat the slow compile times developers often complain about. But there are only so many things that can be done. Ultimately, almost every time an app is compiled most of the code will go through two fairly complicated procedures before the final output is ready. By removing the conversion to Java bytecode, at least one largely unnecessary step can be eliminated. The toolchain is designed to improve build times and simplify development by reducing dependencies on other tools.
References
- https://source.android.com/source/jack.html
- https://software.intel.com/en-us/android/articles/an-introduction-to-jack-and-jill-on-x86
- https://sites.google.com/a/android.com/tools/tech-docs/jackandjill
- http://android-developers.blogspot.com/2014/12/hello-world-meet-our-new-experimental.html
- http://www.androidpolice.com/2014/11/30/jack-and-jill-are-googles-new-compilers-for-android-app-developers