Android compilation optimization to improve your development efficiency

Android compilation optimization

1. Current Situation Analysis

Project compilation is an important part of Android application development. As the size of the project becomes larger and larger, compilation takes longer and longer, which slows down development efficiency.

Full compilation/incremental compilation/installation takes up most of the time in the entire process. Assuming full compilation takes 6 minutes and runs 10 times a day, we waste 60 minutes of compilation time every day. Assuming the compilation time is 3 minutes, every day save 0.5 hours,

Full compilation: The project has not been run, no specific cache file is generated, and the process of compiling and merging resource codes is performed for the first time. For example, after clean. Mostly used for the initial compilation of the project when packaging/cleaning the cache and then compiling.

Incremental compilation: Compile on the basis of full compilation. Changes/additions/deletions/additions will be changed without affecting the overall compiled files. Mostly used for the initial compilation of the project/compilation after generating the cache file.

2. Compilation process

The overall process is as follows

• aapt package resource files, generate R.java, resource.arsc, res, manifest.xml

• aidl generates java interface files

• javac compiles R.java, the java files generated by Aidl and the source code used in the project to generate .class files

• R8 obfuscates and compresses .class files, and generates .dex files through d8

• The apk builder packs the resource pack and .dex into an apk file

• apksigner /jarSigner will sign the apk

3. Compilation time-consuming detection

Build Analyaer

Gradle commands

$ gradlew app:assemble --profile (Windows)

$ ./gradlew app:assembleDebug --profile (Ubuntu,Mac)

scan

$ gradlew app:assemble --scan(Windows)

$ ./gradlew app:assembleDebug --scan(Ubuntu,Mac)

https://gradle.com/s/mshp4gfpxazg6

Android studio

https://juejin.cn/post/7094198918065422350

4. Compilation and optimization routine scheme

5. Big factory plan

Guess you like

Origin blog.csdn.net/m0_64420071/article/details/127535819