Learning ideas

(1) What is input in the packaging process?

(2) What is the output of packaging process?

(3) What tools are used in the packaging process?

The flow chart

  • Look at the compilation and packaging steps

Compile packaging steps

1. Package resource files to generate r. Java files

Aapt (The Android Asset Packaing Tool), SDK \build-tools\25.0.0\aapt.

In this process, both the androidmanifest.xml file and the layout file XML in the project are compiled to generate the corresponding R.java, and the Androidmanifest.xml is compiled into binary by AAPT.

Resources stored in the RES directory of the APP. Most of these resources are compiled into binary files before the APP is packaged, and each of these files is given a Resource ID. The application layer code accesses this type of resource through the Resource ID.

During the compilation process of Android applications, aAPT will compile resource files and generate a resource. Arsc file, which is equivalent to a file index table, records a lot of information related to resources.

2. Process aiDL files and generate corresponding Java files

The tool for processing AIDL files is Android Interface Definition Language (AIDL). The directory is SDK \build-tools\25.0.0\ aiDL.

The AIDL tool parses the interface definition file and generates the corresponding Java code interface for the program to invoke. You can skip this step if you are not using aiDL files in your project.

3. Compile the project source code and generate the class file

Compile source code using the Java compiler (JAVAC)

All Java code in the project, including r.java and.aidl files, will be converted into.class files by the Java compiler (Javac), and the resulting class files will be located in the bin/classes directory of the project.

4. Convert all the class files to generate the classes.dex file

This process uses the dx (dex) tool to generate a classes.dex file that can be executed by the Android Dalvik VM. The tool directory is SDK \build-tools\25.0.0\dx.

Any third-party libraries and. Class files will be converted to. Dex files. The main work of dx tool is to convert Java bytecode to Dalvik bytecode, compress constant pool, eliminate redundant information, etc.

5. Package and generate APK files

Package tools apkBuilder, directory Android-SDK /tools, ApkBuilder for a script file, The actual call is (SDK \ tools \ lib) files in the com. Android. Sdklib. Build. ApkbuilderMain class.

All resources that are not compiled, such as resources in images and assets (such files are original files that are not compiled during APP packaging, but are packaged directly into APP. For access to these resource files, the application layer code needs to access them through the file name);

The compiled resources and.dex files are packaged into the final.apk file by the ApkBuilder tool.

6. Sign the APK file

Once an APK file is generated, it must be signed before it can be installed on the device.

In the development process, the main use is two types of signed keystore. Debug. keystore is used for debugging. The debug.keystore is used for debugging when you run directly in Eclipse or Android Studio.

The other is relese.keystore, which is used to publish the official version and needs to be configured by the developer.

7. Align the signed APK file

If the apK you publish is official, you must align the APK using zipalign, SDK \build-tools\25.0.0\zipalign.

The main process of alignment is to offset all resource files in the APK package to integer multiples of 4 bytes from the start of the file so that APK files can be accessed faster through memory mapping. The purpose of alignment is to reduce runtime memory usage.

Thank you

Android APK packaging process

Android compile package process details

Compile and package the Android application (APK)

Blog.csdn.net/sinat_23030…