Current location - Quotes Website - Personality signature - Does android apk include android basic class library?
Does android apk include android basic class library?
Process overview:

1. Package resource files to generate R.java files.

2. Process aidl files and generate corresponding java files.

3. Compile the engineering source code and generate the corresponding class file.

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

5. Package to generate apk.

6. Sign the apk document.

7. process the signed apk file.

Tools used in the packaging process

name

Functions in the operating system path introduce the source code path.

American association of physics teachers American association of physics teachers

(Android Asset Pack Tool)

Android resource packaging tool

$ { ANDROID _ SDK _ HOME }/build-tools/

ANDROID_VERSION/aapt

Framework \ Foundation \ Tools \aap

aidl

(android interface definition language)

Android interface description language,

Convert aidl into. Java file

$ { ANDROID _ SDK _ HOME }/build-tools/

ANDROID_VERSION/aidl

Framework \ Foundation \ Tools \aidl

JavacJava compiler

${JDK Home Page }/java

C or /usr/bin/javac

Short for DEXEDRINE

Conversion. Class file to Davik virtual machine

Recognizable. Dex file

$ { ANDROID _ SDK _ HOME }/build-tools/

ANDROID_VERSION/dx

apkbuilder

Generate apk data packet

${ANDROID_SDK_HOME}/tools/

apkbuilder

sdk\sdkmanager\libs\sdklib\

src\com\android\sdklib\build\

ApkBuilderMain.java

The signing tool of jarsigner.jar file is $ {JDK _ home}/jarsigner or /usr/bin/jarsigner.

Zipalign bytecode alignment tool

$ {Android _ SDK _ home}/tool

/zipalign

Step 1: package the resource file and generate the R.java file.

Input resource file (that is, file in res in the project), asset file (equivalent to another resource, not optimized by Android system like file in res), AndroidManifest.xml file (read package name from here, because R.java file needs to be generated), and Android basic class library (Android.jar file).

Tools aapt tools

Output the packaged resources (resources.ap_ file in the bin directory) and R.java files (in the gen directory).

Aapt, a tool for packaging resources, most XML resource files in text format will be compiled into XML resource files in binary format, and all other resources will be compiled or processed except the assets packaged in APK and res/raw resources. .

The generation process mainly calls the buildResource () function in the Resource.cpp file in the aapt source directory. This function first checks the legitimacy of AndroidManifest.xml, and then processes the resource subdirectories in the res directory. The processed function is makeFileResource (), which includes the legality check of the resource file name. Add entries to the resource table, etc. After the processing is completed, the compileResourceFile () function is called to compile the resources in the res and asserts directories and generate the resources.arsc file. The compileResourceFile () function is located in the ResourceTable.cpp file in the aapt source directory. Finally, this function will call the parseAndAddEntry () function to generate the R.java file, and then call the compileXmlfile () function to compile the xml file in the subdirectories of the res directory, so that the processed xml file is simply "encrypted". Finally, all resources, compiled resorces.arsc file and "encrypted" AndroidManifest.xml file are packaged and compressed into resources.ap_ file (command line compilation with Ant tool will generate an ap_ file with the same name as the attribute specified by "project name" in build.xml).

For a more detailed process of this step, please read the .android.sdklib.build.apkbuilderman class. Its code implementation is located in the SDK \ sdkmanager \ libs \ sdkblib \ src \ com \ android \ sdkblib \ build \ ApkBuilder.java file of the Android system source code. The code constructs an apkbuilder class, and then generates an apk file based on the file containing resources.arsc, which usually ends with ap_, and then calls the addSourceFolder () function to add engineering resources. addSourceFolder () calls the processFileForResource () function to add resources to the apk file, which includes files in the res directory and the asserts directory. After adding resources, call addResourceFromJar () function to write the dependent libraries into the Apk file, then call addNativeLibraries () function to add native libraries (so or bin files compiled by android NDK) in the project libs directory, and finally call sealApk () to close the apk file.

Step 6: Sign the apk document.

Enter unsigned. Apk file.

Tool jarsigner

Output signed. Apk file

Android applications need to be signed before they can be installed on Android devices. There are two ways to sign apk files: one is to sign when debugging programs, and when developing android programs with eclipse, a debug.keystore will be used to sign APK when compiling debugging programs; The other is to sign the program when it is packaged and released. In this case, you need to provide a signature file that meets the requirements in the android development document. There are also two ways to sign: one is to sign with jarsigner tool provided in jdk; The other is to use the signapk tool provided in the android source code, and its code is located in the build\tools\signapk directory of the android system source code.

Step 7: Align the signed apk file.

Enter the signature. Apk file.

Tool zipper alignment tool

Output aligned. Apk file.

The tool to be used in this step is zipalign, which is located in the android-sdk\tools directory, and the source code is located in the build\tools\zipalign directory of the android system source code. Its main job is to align the spk package so that all resource files in the spk package are offset from the beginning of the file by an integer multiple of 4 bytes. It will be faster to access apk files through memory mapping. The work of verifying whether the apk file is aligned is completed by the verify () function of ZipAlign.cpp file, and the work of handling the alignment is completed by the process () function.

Take specific files contained in specific projects as an example to draw as follows: