Original link http://trickyandroid.com/the-dark-world-of-jack-and-jill/
Last year Google released a new toolchain- Jack(Java Android Compilation tool) and Jill(Jack Intermediate Library Linker), which are used to replace the existing javac+dx toolset.
In this article I will try to organize my thoughts and ideas about this toolchain.
But before I start digging jack&jill, I'm going to go around a small circle and get a high-level overview of the existing Toolchain and describe the compilation process for your beloved Android app.
Android Code compilation 101
Frankly, I'm not going to cover the complete build process-I'm just focusing on the parts that are most relevant to our topic-converting Java source code to dex files.
From the first dinosaur to the Earth, the process of compiling is this:
We start with the Java source code. The purpose is to compile executable instructions that the JVM can understand in these source-generated devices.
For Java (non-Android) applications, we only need the Java compiler (Javac). It can compile Java source code and generate Java binaries (*.class files). Java binaries can be executed by a regular JVM running on your machine.
The problem is, on Android devices, we use non-standard JVMs. We've used the modified version, which has a high level of mobile phone environment. For example, the JVM is called Dalvik(or ART on more efficient L + devices).
Because the modified Jvm,java binary code also needs to be modified, making the Dalvik executable. This is the responsibility of the DX tool-it receives the Java binary code (. class file) and translates it into a binary file (*.dx file) for Android fuel consumption.
It is worth mentioning that when the project contains a third-party library-jar (or AAR) Form-instead of processing, the third-party library is just a compressed collection of *.class files. So a third-party library is fed directly to the DX tool because we don't need to compile it.
It's pretty simple right now, right?
Binary code Processing
Over time, Android developers have become more experienced and people are starting to develop cool tools and plugins that can boost your code (a.k.a bytecode manipulation) at the Java binary level.
You see that you've heard of these more popular tools:
- Proguard
- Jacoco coverage
- Retrolambda
- ... Wait a minute
This gives us a cool ability to post-process our code w/o modify our original code. F.I. Proguard can share your Java bytecode and delete useless parts (also known as minimization). Or Retrolambda instead of a lambda expression with an anonymous inner class Java8, so your lambda expression can work in an Android VM that doesn't support the JAVA8 feature.
The process is as follows:
Each class (its bytecode) is processed by the bytecode processing plug-in, and the result is passed to the DX tool to produce the final result.
Conversion API
As such tools start to blow up, it is clear that the Android Gradle build system is not really designed for bytecode processors-the only way to ' grab ' Java bytecode ready and not be processed by DX , is to add gradle tasks that depend on the existing tasks created by the Android Gradle plugin. The name of the task is implementation details, which are dynamically generated based on the project configuration and constantly evolving with the Android Gradle plugin, which Google continues to update. This causes every new Android plugin to be released, and this plugin does not work properly.
So Google needs to take action. They did-they introduced the transition API-a simple API that allows the converter to be added-the class will be called at the right time for the build process. The input to the conversion is the Java bytecode. This allows plug-in developers to use a number of reliable methods for processing bytecode, thereby stopping the use of private, document-free APIs.
Jack & Jill
At the same time, a mixed blessing, Google's engineers are super busy creating new things and creating things that ruin people's hearts! self-driving car ! Jack and jill!.
Jack -is the compiler. Similar to Javac, but it does something slightly different:
As you can see,Jack compiles the Java source code directly into a DEX file! We are not in the middle of the *.class file, so the DX tool does not need it!
But wait! What if a third-party library (a collection of. class files) is introduced into the project?
Well,Jill should be on the show:
Jill can process the class file and convert it into a special Jayce format that can be used for the Jack compiler's input.
Now, let's calm down and think about ... What is going to happen to the cool tools we indulge in? They all need a. class file, and the Jack compiler doesn't need the. class file ...
Fortunately, Jack provides some important out-of-the-box functionality:
- RETROLAMBDA-no longer needed. Jack can handle lambda expressions properly
- Proguard-has now been incorporated into Jack, so you can still use obfuscation and minimize code.
Then, the list of disadvantages is as follows:
- Jack does not support conversion API-No intermediate Java bytecode can be modified, so some plugins I did not mention will not work
- Jack does not support annotation processing now, so if you rely heavily on libraries such as Dagger,autovalue, switching to Jack needs to think twice. Change , Jack Wharton points out that the N preview version of Jack has supported annotation processing but failed to release it through Gradle.
- The Lint checker, which runs at the Java bytecode level, does not support
- Jack's working more slowly than JAVAC+DX.
- Jacoco not supported-but I personally think Jacoco is suspicious (really not as you think), so you can completely abandon it
- Dexguard-Enterprise Edition is not supported now Proguard
I realized that what I just mentioned was temporary, and Google was actively addressing these issues, but unfortunately, when people began to realize that the actual cost of switching to the new toolchain was so high, all the excitement about the Android-supported JAVA8 feature would be completely faded.
Jack is a cool step forward, and it will give Google more control and flexibility on the build chain, but it is in its infancy and it will take some time to accumulate before it becomes popular.
Yours
Pavel Dudka
- AAR is further than Jar-it also contains data related to Android, such as asset, resources and other jars that are not supported
- Run on the latest n version of Android VM support some JAVA8 instructions
- Jack ' n ' Jill Map proud of it here
[Android] The dark side of Jack and Jill