At compile time, AAPT scans all of the resources you have defined (defined in different files and separate resource files), and then assigns them different resource IDs.
The resource ID is a 32bit number, the format is ppttnnnn, the PP represents the package that the resource belongs to, the TT represents the type of the resource (type), and nnnn represents the name of the resource under this type. For the application's resources, the value of PP is 0x77.
The value of TT and nnnn is arbitrarily specified by the AAPT tool – basically each new resource type is incremented from the previous number (starting at 1), and each new resource entry is incremented from the number 1.
So if our resource files are listed in the following order, AAPT will process them in turn:
<code>layout/main.xml </code>
<code>drawable/icon.xml </code>
<code>layout/listitem.xml</code>
In order, the first resource type is "layout" so specify Tt==1, the first resource under this type is "main", so specify Nnnn==1, and finally this resource is 0x7f010001.
The second resource type is "drawable", so specifying tt==2, "icon" under this type specifies nnnn ==1, so the final resource ID is 0x7f020001.
The third resource type is "layout", and this resource type is already defined in the previous, so TT is still 1, but the name "ListItem" is new, so specify nnnn==2, so the final resource ID is 0x7f010002.
Note that AAPT does not save the last generated resource ID at each compile time, and whenever the/res directory changes, AAPT may go back to assigning an ID number to the resource and then regenerate a R.java file. Therefore, you should not persist the resource ID persisted in the program to the file or database in the process of development. Resource IDs are subject to change after each compilation.
Once the resource is compiled into a binary file, AAPT generates the R.java file and the "RESOURCES.ARSC" file, "R.java" is used for compiling the code, and "RESOURCES.ARSC" contains all the resource names, The resource ID and the contents of the resource (for a resource of a separate file type, this content represents the path information for this file in its. apk file). This corresponds to the resource ID in the running environment and the specific resource.
When debugging, you can use "AAPT Dump resources <apk path >" To see a detailed description of the RESOURCES.ARSC file.