+1

Jack & Jill: Android Tool Chain

rsz_jack-and-jill-nursery-rhymes.jpg

Introduction of "Jack & Jill"

Jack & Jill are the new compilers for the Android developers is brought to you by Google. This is an experimental Android 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.

Anyway, it's now deprecated according to this announcement.

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 available in AOSP(Android Open Source Project).

rsz_2jack-overview.png

  • 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.

pre-dex.png

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.

jill.png

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.

Untitled Diagram.png

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

  1. https://source.android.com/source/jack.html
  2. https://software.intel.com/en-us/android/articles/an-introduction-to-jack-and-jill-on-x86
  3. https://sites.google.com/a/android.com/tools/tech-docs/jackandjill
  4. http://android-developers.blogspot.com/2014/12/hello-world-meet-our-new-experimental.html
  5. http://www.androidpolice.com/2014/11/30/jack-and-jill-are-googles-new-compilers-for-android-app-developers

All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí