Apk file is an Android application package file format, and its essence is a compressed file. Drag the apk file into Android Studio to view its contents, as shown in the following figure:
From the above figure, we can see several important components in the apk package:
The classic flow chart of the packaging process is as follows:
Among them, seven oval contents correspond to seven important steps in the packaging process and seven important tools in the packaging, as follows:
Further explain the above seven important packaging processes.
Aapt packages resource files and generates R.java files, resources.arsc and other files.
Aapt will check the legality of the AndroidManifest.xml file before packaging the resource file, and scan the legality of the resource directory under the res directory, so if there is a problem with resource naming, it will directly report an error at the compilation stage.
It should be noted that the xml file will be compiled into binary, so we can't directly open the xml file in the apk package.
AIDL is an Android interface definition language and a way to realize communication between Android processes.
In this step, the aidl file will be processed to generate a java file.
Compile java files through javaCompiler to generate class files.
Dx tool converts the class file into a Dex file executable by Dalvik virtual machine of Android system.
Package all files such as classes.dex and res folders into apk files.
The APK package needs to be signed after it is generated, and we need to configure it ourselves to publish the signature.
There are two common signature methods: jarsigner and apksigner.
Zipalign is a sorting tool for APK file alignment on Android platform, which can align uncompressed data in APK with 4 bytes.
It should be noted that the order of alignment processing is different according to different signature methods.
Memorandum of APK packaging process.