Simple Build flowchart
The official website gives us a very simple picture of compiling, packaging, apk generated content, and signature. The picture outlines a general process from project to run to device or simulator, and we also see a complete apk containing the following: one or more dex files, RESOURCES.ARSC, Non-compiled resource files and androidmanifest.xml files, etc.
Detailed Build flowchart
The official website gives us a very clear package flowchart:
To compile the packaging steps:
1. Packaging resource files, generating R.java files
The tools for packaging resources are AAPT (the Android Asset packaing tool) (E:\Documents\Android\sdk\build-tools\25.0.0\aapt.exe).
In this process, the Androidmanifest.xml file and the layout file XML in the project are compiled, then the corresponding R.java is generated, and Androidmanifest.xml is compiled into binary by AAPT.
A resource stored in the app's res directory, which is mostly compiled before the app is packaged, becomes a binary file, and assigns a resource ID to each of those files. for access to this class of resources, the application layer code is accessed through the resource ID . Android app during compilation the AAPT tool compiles the resource file and generates a RESOURCE.ARSC file, RESOURCE.ARSC file is equivalent to a file index table, which records a lot of resource-related information.
2. Process the Aidl file and generate the appropriate Java file
The tool used in this process is Aidl (Android Interface Definition Language), which is the Android Interface Description Language (E:\Documents\Android\sdk\build-tools\ 25.0.0\aidl.exe).
The Aidl tool parses the interface definition file and generates the appropriate Java code interface for the program to call. If you do not use the Aidl file in your project, you can skip this step.
3. Compile the project source code, generate the class file
All Java code in the project, including the R.java and . Aidl files, is compiled into a . class file by the Java compiler (JAVAC), and the resulting class file is located in the project's bin/ The classes directory.
4. Convert all class files, generate Classes.dex files
The DX tool generates a Classes.dex file that can be executed by the Android system Dalvik virtual machine, which is located (E:\Documents\Android\sdk\build-tools\25.0.0\dx.bat).
Any third-party libraries and . Class files will be converted to . Dex files. The main work of DX tool is to convert Java bytecode into Dalvik bytecode, compression constant pool, eliminate redundant information and so on.
5. Package Build APK file
All resources not compiled, such as images, assets directory resources ( the file is some raw files, the app is packaged without compiling it, but directly packaged into the app, for this type of resource file access, the application layer code needs to access it through the file name ), compiled resources and . Dex files are packaged into the final . apk file by the Apkbuilder tool.
The packaged tool Apkbuilder is located in the Android-sdk/tools directory. Apkbuilder is a script file that is actually called the Com.android.sdklib.build.ApkbuilderMain class in the (E:\Documents\Android\sdk\tools\lib) file.
6. Sign the APK file
Once the apk file is generated, it must be signed to be installed on the device.
In the development process, the main use is two kinds of signature keystore. One is the Debug.keystore for debugging, which is used primarily for debugging, and running on the phone in eclipse or Android studio is the use of debug.keystore.
The other is for the release of the official version of KeyStore.
7. Align the signed apk file
If you release the APK is the official version, you have to align the apk, the use of the tool is Zipalign (E:\Documents\Android\sdk\build-tools\25.0.0\zipalign.exe)
The main process of alignment is to offset all the resource files in the APK package from the file starting at 4-byte integer times, which makes it faster to access the APK file through a memory map. The effect of alignment is to reduce the use of memory at run time.
Android APK Packaging Process