Android APP compilation flow

Android Gradle plugin specific processes

  • First, on an official map:
    Here Insert Picture Description
  1. Firstly aapt packaged res resource files, generate R.java, resources.arsc and res files (binary & maintain the original non-binary code)
  2. .Aidl processing file, corresponding to a Java interface file generated
  3. By Java Compile compile R.java, java interface file, generates .class file
  4. By dex command, the .class file .class files and third-party libraries in the process of generating classes.dex file
  5. Apkbuilder generated by the aapt CompiledResources and other resource files and package generated apk file classes.dex
  6. , To carry out the above apk debug or release signature tool by Jarsigner
  7. The apk after signature by zipalign alignment processing tool
  • Construction flowchart:
    Here Insert Picture Description
    1. The compiler converts the source code into dex file (including byte code Android device), converts all else compiled into the resource
    2.APK packer will DEX files and resources into a single compiled APK, however, you must first sign the APK, before the application is installed and deployed on Android devices
    3.APK packaged using debug or release signing key to sign the library APK (divided debug and release versions)
    4. before the final generation of APK , the packer will use the tool to zipalign applications optimized to reduce memory consumption when running on the device

Construct

  • android gradle plugin mainly used com.androi.application and com.android.library, both the corresponding class respectively com.android.build.gradle.AppPlugin, the corresponding class is com.android.library plug com.android .build.gradle.LibraryPlugin
  • Function execution process
apply()->configureProject()->configureExtension()->createTasks()->createAndroidTasks()

Gradle life cycle

  • Initialization phase, the implementation of settings.gradle, and build.gradle transformation within each project subject to Project

  • Configration stage configuration corresponding Project object code build.gradle performed, after the end Configuration stage, the entire project and build relationships within the Task would determine, Configuration described creates a dependency between the Task to FIG.

  • Implementation phase: the implementation of the corresponding task

  • Each life cycle can hook

  • Can set different gradle, for use in the local and remote setting may be different introduce different moudle

  • It may be defined in various variants build.gradle may be used provided the use of local or remote moudle moudle

  • May be inserted before any of their Task Task, deletions java code is compiled, byte code modification, various plugin, hook execution code is here, and can also make hot-swappable module, optimizing compiler speed

R file refers to the real resource file

  • aapt tool generates a displacement of ID for each resource files, which are stored in the ID file R.java
//资源ID是一个4字节表示的无符号整数,在R.java文件中用16进制表示,其中,最高的1字节表示Package ID, 次高1个字节表示TypeID, 最低2字节表示Entry ID
public final class R {
    public static final class anim {
        public static final int abc_fade_in=0x7f050000;
        public static final int abc_fade_out=0x7f050001;
        public static final int abc_grow_fade_in_from_bottom=0x7f050002;
      
    }
    public static final class animator {
        public static final int design_appbar_state_list_animator=0x7f060000;
        public static final int slide_in_left=0x7f060001;
        public static final int slide_out_left=0x7f060002;
    }
  • aapt while generating also generates the ID of a file resources.arsc, corresponding to a resource index table, key resource ID of the table, a value of path resources in apk
  • So by R.java and resources.arsc file can refer to the actual resource file

Alignment optimization

  • In the above process involves packing into alignment word, compiling principles learned through the memory alignment, where 4 * n bytes if the start position of each resource is a resource after, the next visit is not a resource need to traverse, skip to 4 * n bytes and determines the timestamp of resources to (random access array faster than a linked list)

Guess you like

Origin blog.csdn.net/qq_39424143/article/details/95094949