Jack and Jill are new build tools introduced by Google that optimize the Android build process. Jack compiles Java code to an intermediate format called Jayce bytecode. Jill then compiles Jayce to optimized Dalvik bytecode. This results in faster build times, smaller app sizes, and support for Java 8 language features on older Android versions. It also allows for new optimizations from tools like ProGuard and DexGuard during the build. The changes improve performance for developers and applications.
15. LOCAL int n
FOR_STATEMENT:
- EXPRESSION_STATEMENT:
- ASG_OPERATION:
- LOCAL_REF i
- INT_LITERAL 0
- LT_OPERATION:
- LOCAL_REF i
- INT_LITERAL 8
- POSTFIX_INC_OPERATION:
- LOCAL_REF i
- ...
LOCAL int n
FOR_STATEMENT:
- EXPRESSION_STATEMENT:
- ASG_OPERATION:
- LOCAL_REF i
- INT_LITERAL 0
- LT_OPERATION:
- LOCAL_REF i
- INT_LITERAL 8
- POSTFIX_INC_OPERATION:
- LOCAL_REF i
- ...
Code representations
for (int i = 0; i < 8; i++) ...for (int i = 0; i < 8; i++) ...
iconst 0
istore v0
iload v0
bipush 8
ificmpge +12
...
iinc v0, 1
goto -12
iconst 0
istore v0
iload v0
bipush 8
ificmpge +12
...
iinc v0, 1
goto -12
.class .dex
.java
Javac
.jayce
Jack
const/4 v0, #0
const/16 v1, #8
if-ge v0, v1, 8
...
add-int/lit8 v0, v0, #1
goto -9
const/4 v0, #0
const/16 v1, #8
if-ge v0, v1, 8
...
add-int/lit8 v0, v0, #1
goto -9
Jill
Jack
16. Implications of Jack and Jill
● Java annotation processors – supported in Jack
E.g. Dagger, Butterknife
● Bytecode processors – only supported via Jill
E.g. JaCoCo, Retrolambda
● Other JVM languages – only supported via Jill
E.g. Scala, Groovy, Dart
● Instant Run – not supported yet
17. Implications of Jack and Jill
Libraries
(.jayce)
Jack
Assets
Compiled
XML resources
(.xml)
Aapt
Dalvik bytecode
(classes.dex)
Javac annotation processors
E.g. Dagger, Butterknife
Source code
(.scala,...)
Libraries
(.class)
XML resources
(.xml)
Assets
Runtime
(.class)
Jill
Jill Runtime
(.jayce)
Bytecode processors
Java bytecode
(.class)Scalac
Application
(.jayce)Jill
22. Java 8: default methods
● In your own code:
● In the Android runtime:
public interface java.util.List<E> extends java.util.Collection<E> {
public abstract int size();
...
public default void sort(java.util.Comparator<? super E>) {
.....
}
}
public interface java.util.List<E> extends java.util.Collection<E> {
public abstract int size();
...
public default void sort(java.util.Comparator<? super E>) {
.....
}
}
public interface Foo {
public abstract void someMethod();
public void someDefaultMethod() {
....
}
}
public interface Foo {
public abstract void someMethod();
public void someDefaultMethod() {
....
}
}
Only on
Android N
30. Conclusions
● Huge changes
● Clean implementation
● Different build process
● New intermediary representation
Internally
For languages and tools
31. Conclusions
● Huge changes
● Clean implementation
● More efficient builds
● Java 8
● Different build process
● New intermediary representation
Internally
For languages and tools
For app developers
32. Further reading
● “Experimental New Android Tool Chain - Jack and Jill”
http://tools.android.com/tech-docs/jackandjill
● “Java 8 Language Features”
https://developer.android.com/preview/j8-jack.html
● “Jack (Java Android Compiler Kit)”
https://source.android.com/source/jack.html
● AOSP repository
https://android.googlesource.com/toolchain/jack/
● “State of the ART”
http://androidbackstage.blogspot.com/2016/03/episode-45-state-of-art.html