APK file structure

APK (Android Package) file is a compressed file called .apk suffix of, APK file contains all the contents of an Android application, the Android platform file used to install the application.

  • assets stored need to be packaged into static files of APK
  • lib store application depends on the native library
  • res store the application's resource file
  • META-INF store signature and certificate applications
  • AndroidManifest.xml application configuration file
  • classes.dex DEX executable file
  • resources.arse mapping relationship between resource index table, the resource file and resource record ID

res

Is the abbreviation resource, storage resource file, all files exist in this folder will be mapped to the Android project in .R file, generates a corresponding ID, when accessing the direct use of resources ID, a R.id.filename.
at res folder can contain a plurality of folders, wherein

  • aim Animation files stored
  • drawable Directory for image resources
  • layout Directory for file layout
  • valuesDirectory store some characteristic values, colors.xmlstored color color values, dimens.xmldefine the size of the value, string.xmlthe value defined string, styles.xmldefined style object
  • xmlXml folder to store any file can be read by Resources.getXML () at runtime
  • rawIt can be assigned directly to any of the files on the device, without compiling

lib

Stored application-dependent native libraries, typically written in C / C ++, where the library may contain a different type lib 4, depending on the type of CPU, it can be divided into ARM, , ARM-v7a, MIPS, X86correspond to the ARM architecture, ARM- V7 architecture, MIPS architecture and X86 architecture.

Different CPU architectures corresponding to different directories, each directory can put a lot so the corresponding version of the library, and the fixed structure of the directory, users can store their library so according to this directory. Currently mobile terminal used on the market are mostly based on ARM architecture or ARM-V7a, X86 and MIPS architectures of mobile intelligent terminal is relatively small, so some applications lib directory contains only armeabi armeabi-v7a directory or directory.

META-INF

Save signature information of the application, the signature information can verify the integrity of APK files. AndroidSDK APK calculates the integrity of all files in the package during packaging APK, integrity and save these to the META-INF folder, the application will first check the integrity of the clip according to APK META-INF files in the installation so that we can ensure that every file in the APK is not to be tampered with. APK in order to ensure that the application has not been maliciously modified or viral infection, help ensure the security and integrity of the system of Android applications.

META-INF directory that contains the file under there CERT.RSA, CERT.DSA, CERT.SFand MANIFEST.MF, which is CERT.RSA developers to take advantage of the private key to sign the APK signature file, CERT.SF, MANIFEST.MF recorded the SHA-1 hash value of the file in the file .

AndroidManifest.xml

Android is the application's configuration file is used to describe Android application "overall information" setting file, in simple terms, the equivalent of Android applications to Android system "self-introduction" of the configuration file, the Android system can be based on this "self introduction "APK complete understanding of iT applications, each Android application must contain a AndroidManifest.xml file, and its name is fixed and can not be modified.

We generally regard the code for each Activity, Service, Provider and Receiver registered in Android application development time in AndroidManifest.xml, the only way to start the corresponding system components, this file also contains some additional rights declaration and use SDK version information, and so on.

When packaged, the compiler will AndroidManifest.xml simple, easy to recognize the Android system, after compiling the format is AXML format, as shown below:

AXML head : fixed represented AXML file, which is a fixed value 0x00080003
AXML file length : identifies the file size AXML
StringDataSegment : XML document, all saved in this string types.
ResourceIdSegment : Resource File ID xml file is saved in a statement here.
XmlContentSegment : xml content segment is, in accordance with the xml file structure are sequentially arranged, stored in the xml data content.

classes.dex

Traditional Java program, first put Java files compiled into class files, byte code are stored in the class file, Java virtual machine can perform these class files through interpretation.

Dalvik virtual machine is the Java virtual machine optimized Dalvik bytecode is executed, bytecode Dalvik which is converted from Java bytecode, under normal circumstances, Android application when the package through AndroidSDK dx tool converts Java bytecode into Dalvik bytecode.

dx tools can be combined to a plurality of class files, recombinant, optimization can be achieved to reduce the volume, the purpose of shortening the running time. Dx tool conversion process, as shown below:

As shown above, dx tool the contents of each region of each of the .class files to be heavy, recombinant, generates optimized file dex rearrangement dex files can be generated in the Dalvik virtual machine execution, and faster.

resources.arsc

Used to record the mapping relationship between resource files and resource ID, it used to find the resources according to the resource ID.

Android was developed sub-module, specifically res directory used to store the resource file, when in the code needs to call the resource file, just call findviewbyId () can get the resource file whenever the res folder to place a file, aapt will automatically generate the corresponding ID stored in the .R file, we can call this ID, only this ID is not enough, .R file only to ensure that the compiler not being given, in fact, the program is running, the system according to ID to find corresponding resource path and is used to record file file resources.arsc ID and resource files such position corresponding relationship.


Reprinted from above https://blog.csdn.net/aha_jasper/article/details/104944929

Guess you like

Origin www.cnblogs.com/huaranmeng/p/12595135.html