Android compilation flow basis

Preface: This article is the study notes, record Android knowledge, we will study together.

Android build engineering package is a very complex process, involving engineering source code, resource files, AIDL files, and library files to compile the project relies on the conversion. Compilation process is very flexible, so understanding some of the underlying how they work.

From Google to find the official website to build a typical flow chart:
Here Insert Picture Description

https://developer.android.com/studio/build/index.html?hl=zh-cn

Introduce the four steps compiler construction:
code compiler -> Code synthesis -> Resources Packaging -> Signature and alignment
(1) Java compiler to compile the project code resources, including a code resource App source code, apt R compiler-generated files and AIDL file generated Java interface file. Xxx.class file generated by the Java compiler.
Third-party libraries (2) by dex tool that will xxx.class file and project dependencies to generate virtual machine dex executable file, if you use MultiDex, will have more dex files, all class files containing compiled, also including its own .class files and dependencies .class files.
(3) apkbuilder tool resource files .dex files, resource files after compilation apt, dependent on third-party library package generated signature aligned apk file.
(4) and Zipalign Jarsigner sign a file and alignment operation, and ultimately generate apk file.

Task can see the situation of each running through Gradle tool, you can also see the Gradle compilation process, show detailed Task consuming each task.

  • Run init scripts: Initialization Description
  • Configure settings: a module configured to check settings.gradle
  • Configure build: Check build.gradle introduced classpath
  • Calculate task graph: calculated dependent on each module
  • Run tasks: task start building

If you want to see the Task dependency tree, is recommended to use a framework Gradle Gradle-Task-Tree , you need to configure build.gradle root:
Here Insert Picture Description
After configuration, use Gradle command in the Terminal:

gradlew assembledebug taskTree --no-repeat

This command prints out the Task dependency tree in the Terminal:
Here Insert Picture Description
can clearly see how our build process is like.

Note the following:
(1) Be sure to use -no-repeat, or will be repeated printing
(2) Gradle configuration requires 3.3 or later
(3) project all referenced module should be configured apply plugin: "com. dorongold.task-tree ".

Further there is provided a visualization tool Gradle-visteg , arranged following code build.gradle root directory:
Here Insert Picture Description
After synchronization the Gradle, gradle build run command, after waiting for a while, after compilation file generated visteg.dot:
Here Insert Picture Description
DOT is a description of file, you can browse through the WPS and other tools, the following is an example:
Here Insert Picture Description
you can see the progressive compilation flow.

Published 87 original articles · won praise 161 · views 870 000 +

Guess you like

Origin blog.csdn.net/woshizisezise/article/details/102824843