A layout file processing method, device and equipment and storage medium
By optimizing the layout files in the APK, especially by replacing strings in the string constant pool array and processing namespaces and offset arrays, the problem of excessively large APK package size was solved, achieving a greater reduction in package size.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-10
- Publication Date
- 2026-03-17
AI Technical Summary
While existing Android application package (APK) optimization solutions have optimized image files and string names, the package size is still relatively large and needs further reduction.
The layout file in the APK is optimized by methods including identifying the string constant pool array and attribute value resMap array in the target layout file, replacing identical strings with empty strings, and processing namespace and offset arrays as necessary to further optimize the layout file.
It effectively reduces the size of the APK package by removing redundant and duplicate information in the layout file, thus achieving greater optimization of package size.
Smart Images

Figure CN115705211B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of data processing, and in particular to a method, apparatus, device, and storage medium for processing layout files. Background Technology
[0002] With the improvement of business iteration development efficiency, the phenomenon of explosive growth in the size of Android application packages (APKs) has become increasingly serious. In order to reduce the size of APKs, more and more package size optimization solutions have emerged.
[0003] Since image files make up a large proportion of the size of APKs, current package size optimization solutions generally focus on optimizing image files. In addition, since string name obfuscation is similar to Java code obfuscation, current package size optimization solutions also optimize the string names of files.
[0004] However, we found that even after optimizing the APK's package size by considering both image files and file string names, the optimized APK still remained relatively large. Therefore, how to further optimize the APK's package size to reduce its overall size is a pressing technical problem that needs to be solved. Summary of the Invention
[0005] To solve the above-mentioned technical problems, or at least partially solve them, this disclosure provides a method for processing layout files, which further reduces the package size of the APK by optimizing the layout files in the APK.
[0006] Firstly, this disclosure provides a method for processing layout files, the method comprising:
[0007] Determine the string constant pool array and the attribute value resMap array in the target layout file;
[0008] The string in the resMap array is selected as the target string;
[0009] Replace any string in the string constant pool array that has the same name as the target string with an empty string.
[0010] In one optional implementation, the method further includes:
[0011] Replace the namespace strings in the string constant pool array with empty strings.
[0012] In an optional implementation, before replacing the namespace string in the string constant pool array with an empty string, the method further includes:
[0013] Identify the namespace nodes in the target layout file;
[0014] Retrieve the namespace name and namespace value from the namespace node;
[0015] Based on the namespace name and the namespace value, the namespace string in the string constant pool array is determined.
[0016] In one optional implementation, the method further includes:
[0017] Determine the offset array in the target layout file corresponding to the string constant pool array; wherein, the offset value in the offset array is used to indicate the storage location of the string corresponding to the offset value in the string constant pool array;
[0018] In the offset array, determine the offset values corresponding to the empty strings in the string constant pool array, and determine the target offset value from the offset values corresponding to the empty strings.
[0019] Modify the offset values in the offset array that correspond to the empty string to the target offset value.
[0020] In one optional implementation, the target offset value includes the offset value corresponding to the first empty string in the empty string.
[0021] In one optional implementation, the target layout file is any layout file in the Android application package (APK) to be optimized, and the layout file is a binary file used to describe the interface display content in the APK to be optimized;
[0022] After replacing the string with the same name as the target string in the string constant pool array with an empty string, the method further includes:
[0023] After obtaining the replacement layout file corresponding to each layout file in the APK to be optimized, the optimized APK is generated based on each replacement layout file.
[0024] Secondly, this disclosure provides a layout file processing apparatus, the apparatus comprising:
[0025] The first determining module is used to determine the string constant pool array and the attribute value resMap array in the target layout file;
[0026] The second determining module is used to determine the string in the resMap array as the target string;
[0027] The first replacement module is used to replace the string with the same name as the target string in the string constant pool array with an empty string.
[0028] Thirdly, this disclosure provides a computer-readable storage medium storing instructions that, when executed on a terminal device, cause the terminal device to implement the above-described method.
[0029] Fourthly, this disclosure provides an apparatus comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the method described above.
[0030] Fifthly, this disclosure provides a computer program product comprising a computer program / instruction that, when executed by a processor, implements the method described above.
[0031] The technical solution provided in this disclosure has the following advantages compared with the prior art:
[0032] This disclosure provides a method for processing layout files. First, the string constant pool array and attribute value resMap array in the target layout file are determined. Then, the strings in the resMap array are identified as target strings. Next, strings in the string constant pool array with the same name as the target string are replaced with empty strings. Therefore, this disclosure reduces the package size of the APK containing the target layout file by replacing some strings in the string constant pool array with empty strings. Attached Figure Description
[0033] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0034] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0035] Figure 1 A schematic diagram of the contents of a layout file provided in an embodiment of this disclosure;
[0036] Figure 2 A flowchart illustrating a layout file processing method provided in this embodiment of the disclosure;
[0037] Figure 3A flowchart illustrating another method for processing layout files provided in this embodiment of the disclosure;
[0038] Figure 4 A flowchart illustrating another layout file processing method provided in this embodiment of the disclosure;
[0039] Figure 5 A schematic diagram of the contents of another layout file provided in an embodiment of this disclosure;
[0040] Figure 6 A schematic diagram of the structure of a layout file processing apparatus provided in an embodiment of this disclosure;
[0041] Figure 7 This is a schematic diagram of the structure of a layout file processing device provided in an embodiment of the present disclosure. Detailed Implementation
[0042] To better understand the above-mentioned objectives, features, and advantages of this disclosure, the solutions disclosed herein will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described herein can be combined with each other.
[0043] Numerous specific details are set forth in the following description in order to provide a full understanding of this disclosure, but this disclosure may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some, and not all, of the embodiments of this disclosure.
[0044] Currently, there are two main directions for optimizing the size of Android application packages (APKs): First, since image files account for a large proportion of the size of APKs, the focus is on optimizing the size of image files in APKs; second, since string name obfuscation is similar to Java code obfuscation, it is relatively easy to think of reducing the size of APK packages by obfuscating string names.
[0045] However, the inventors found that even after optimizing the APK package size from the two directions mentioned above, the optimized APK package size was still relatively large. Therefore, the inventors considered whether there were other directions that could optimize the APK package size.
[0046] To better optimize the APK package size, it's first necessary to understand the content distribution of the resource file directory `res` within the APK, in order to analyze other potential optimization directions. Taking the following version of an application's APK as an example, Table 1 summarizes the file types and sizes contained in this version of the application's APK, specifically sorted by the number of files:
[0047]
[0048] Table 1
[0049] As can be seen, the size of the layout file in the layout directory of this version of the application's APK (12.2 + 8.5 = 20.7 MB) has exceeded that of the image file (19.5 MB). Therefore, the inventor thought of whether the APK package size could be optimized from the perspective of the layout file to further reduce the size of the APK package.
[0050] Therefore, the inventors need to further analyze the layout files in the APK. However, since layout files are binary files compiled from XML files, understanding and modifying binary files is quite difficult. Furthermore, because layout files carry the application's UI display functionality and are of high importance, modifying them carries significant risk. Therefore, based on the aforementioned technical difficulties, no solution has yet been found to optimize the APK's package size by focusing on the layout files.
[0051] The inventors of this disclosure, through analysis of layout files in an APK, discovered that the package size of an APK can be optimized by focusing on the layout files. Specifically, the inventors found that each layout file in an APK includes a string constant pool array and a resMap attribute value array. The string constant pool array stores constants in the APK, and the resMap array stores attributes and integer ID values used to implement the user interface (UI) display in the APK. Taking any layout file in the APK as an example... Figure 1 The diagram shown is a schematic representation of the contents of a layout file provided in an embodiment of this disclosure. The ① part includes a string constant pool array, which contains 8 elements; the ② part refers to the array name of the resMap attribute value array, i.e., the array resMap; the ③ part includes 5 attributes in the resMap array and their corresponding integer id values. For example, layout_width is an attribute, and its corresponding integer id value is (10100F4h).
[0052] Analysis of the publick.xml file in the APK reveals a correspondence between "layout_width" and the integer id value "10100F4h," which matches the correspondence in the resMap array of the layout file. Further analysis of the APK's source code shows that each attribute corresponds to an integer id value. After parsing the XML file using parseXml() to obtain the node elements, the corresponding attribute value is directly retrieved based on the integer id value, rather than the attribute string name. Therefore, the inventors determined that duplicate information exists in the layout file, and that removing this duplicate information can optimize the layout file, thereby reducing the APK size.
[0053] To address this, the inventors devised a method to replace strings with the same names in the string constant pool array of the layout file and the string names in the resMap array with empty strings, thereby removing duplicate information in the layout file, reducing the size of the APK package, and thus optimizing the APK package size.
[0054] Specifically, first, the string constant pool array and attribute value resMap array in the target layout file are determined. Then, the strings in the resMap array are identified as target strings. Subsequently, strings in the string constant pool array with the same name as the target string are replaced with empty strings. It is evident that this embodiment of the disclosure reduces the package size of the APK to which the target layout file belongs by replacing a portion of the strings in the string constant pool array of the target layout file with empty strings.
[0055] Based on this, the present disclosure provides a method for processing layout files, referring to... Figure 2 The above is a flowchart of a layout file processing method provided in an embodiment of this disclosure. The method includes:
[0056] S201: Determine the string constant pool array and the attribute value resMap array in the target layout file.
[0057] In this embodiment of the disclosure, the target layout file can be any layout file in the Android application package (APK) to be optimized, and the layout file in the APK to be optimized is a binary file used to describe the interface display content in the APK to be optimized.
[0058] In this embodiment of the disclosure, the layout file in the APK to be optimized typically includes a string constant pool array and an attribute value resMap array. The string constant pool array is used to store constants in the APK to be optimized, while the resMap array is used to store attributes and integer id values in the APK to be optimized that implement the user interface (UI) display.
[0059] In this embodiment of the disclosure, after determining the target layout file in the APK to be optimized, the string constant pool array and resMap array in the target layout file are determined in order to optimize the target layout file and thereby reduce the package size of the APK to be optimized.
[0060] S202: Determine the string in the resMap array as the target string.
[0061] In this embodiment of the disclosure, after determining the resMap array in the target layout file, the string in the resMap array is determined as the target string, which is used to optimize the target layout file.
[0062] Assuming the target layout file is as follows Figure 1 As shown, the resMap array in the target layout file includes five strings in part ③, namely enabled, gravity, background, layout_width, and layout_height. In this embodiment, these five strings are identified as target strings for optimizing the target layout file.
[0063] S203: Replace the string in the string constant pool array that has the same name as the target string with an empty string.
[0064] In this embodiment of the disclosure, after determining the target string in the resMap array, a string with the same name as the target string is determined in the string constant pool array. For example... Figure 1 The first five strings in section ① shown—enabled, gravity, background, layout_width, and height—have the same names as the target string. To reduce duplicate information in the target layout file, strings with the same names as the target string in the string constant pool array can be replaced with empty strings, thus optimizing the target layout file and reducing the size of the APK package.
[0065] It's worth noting that, typically, the strings in the string constant pool array with the same name as the target string are the first N strings in the string constant pool array, where N is the same as the number of target strings. For example... Figure 1As shown, the strings in the string constant pool array that have the same name as the five target strings in the resMap array are the first five strings in the string constant pool array.
[0066] Therefore, in order to improve the processing efficiency of layout files, after determining the number of target strings (let's say N), the first N strings in the string constant pool array can be replaced with empty strings.
[0067] In this embodiment, after replacing the target string in the string constant pool array of each layout file in the APK to be optimized with an empty string, the replaced layout file is obtained for each layout file. Then, based on each replaced layout file, the optimized APK is generated. Since the APK to be optimized typically includes thousands of layout files, performing the above-mentioned empty string replacement for each layout file can achieve a significant reduction in the APK package size, greatly reducing the package size of the optimized APK.
[0068] In the layout file processing method provided in this embodiment, firstly, the string constant pool array and the attribute value resMap array in the target layout file are determined. Then, the strings in the resMap array are identified as target strings. Subsequently, strings in the string constant pool array with the same name as the target string are replaced with empty strings. It can be seen that this embodiment reduces the package size of the APK to which the target layout file belongs by replacing some strings in the string constant pool array of the target layout file with empty strings.
[0069] Further analysis of the layout files revealed that namespace strings within them are typically quite long, and each layout file contains at least one such string, which appears frequently. Furthermore, the analysis showed that the namespace strings for attributes are not parsed when retrieving attribute values during the APK's user interface display process. In other words, the namespace strings are redundant information within the layout files. In fact, verification confirmed that deleting the namespace strings from the layout files does not affect the normal display of the APK's user interface.
[0070] Therefore, based on the above embodiments, in order to further reduce the size of the APK package, this disclosure also provides a method for processing layout files, referring to... Figure 3 The following is a flowchart of another layout file processing method provided in this disclosure embodiment, wherein the method includes:
[0071] S301: Determine the string constant pool array and the attribute value resMap array in the target layout file.
[0072] S302: Determine the string in the resMap array as the target string.
[0073] S303: Replace the string in the string constant pool array that has the same name as the target string with an empty string.
[0074] S301-S303 in this embodiment are the same as S201-S203 in the above embodiments, and can be understood by referring to the description in the above embodiments, and will not be repeated here.
[0075] S304: Replace the namespace string in the string constant pool array with an empty string.
[0076] In this embodiment of the disclosure, the namespace string is used to describe the namespace of the layout file. The namespace string includes a namespace name and a namespace value. The namespace name is, for example, "Android". The namespace value is, for example, "http: / / schemas.android.com / apk / res / android".
[0077] In one alternative implementation, since namespace values typically begin with "http: / / ", the namespace string in the string constant pool array can be determined based on this "http: / / " prefix. Specifically, the string in the string constant pool array that begins with "http: / / " is identified as the namespace value, and the namespace name corresponding to this namespace value is typically the string preceding it.
[0078] like Figure 1 As shown, the last string in the string constant pool array is the namespace value, and the string preceding it is the namespace name. The namespace string is composed of the two strings: the namespace value and the namespace name.
[0079] In another optional implementation, the layout file also includes a namespace node `startNs`, which records the namespace name and namespace value. For example... Figure 1 As shown, startNs records<Android=“http: / / schemas.android.com / apk / res / android”> This embodiment of the disclosure can determine the namespace string summarized in the string constant pool array based on the namespace name and namespace value recorded in startNs.
[0080] In practical applications, firstly, the namespace node startNs in the target layout file is determined. Then, the namespace name and namespace value in the namespace node are obtained. Finally, based on the namespace name and namespace value, the namespace string in the string constant pool array is determined.
[0081] For example, based on Figure 1 The startNs shown are recorded<Android=“http: / / schemas.android.com / apk / res / android”> This allows us to determine the two strings in the string constant pool array: the namespace name "Android" and the namespace value "http: / / schemas.android.com / apk / res / android".
[0082] In this embodiment of the disclosure, after determining the namespace string in the string constant pool array, the namespace string is replaced with an empty string to further optimize the layout file.
[0083] The present invention does not restrict the execution order of S304. Specifically, S304 can be executed before S302 and S303, after S302 and S303, or in parallel with S302 and S303.
[0084] In the layout file processing method provided in this embodiment, in addition to optimizing the strings in the string constant pool array that are the same as those in the resMap array, the namespace strings in the string constant pool array can also be optimized, further reducing the size of the APK package.
[0085] Through further analysis of the layout file, the inventors discovered that the string constant pool array has a corresponding offset array, and the offset values in the offset array are used to indicate the storage location of the string corresponding to that offset value in the string constant pool array. Since the offset values corresponding to empty strings in the string constant pool array all point to empty strings, the inventors considered whether it was possible to optimize the layout file by merging the various empty strings in the string constant pool array into a single empty string, and simultaneously making the offset values in the offset array corresponding to each empty string point to the merged empty string.
[0086] Therefore, this disclosure also provides a method for processing layout files, referring to... Figure 4 The diagram shown is a flowchart of another layout file processing method provided in this disclosure, wherein the method includes:
[0087] S401: Determine the string constant pool array and the attribute value resMap array in the target layout file.
[0088] S402: Determine the string in the resMap array as the target string.
[0089] S403: Replace the string in the string constant pool array that has the same name as the target string with an empty string.
[0090] S404: Replace the namespace string in the string constant pool array with an empty string.
[0091] The implementation of S401-S404 in this embodiment is the same as that of S301-S304 in the above embodiment. They can be understood by referring to the description in the above embodiment, and will not be repeated here.
[0092] S405: Determine the offset array in the target layout file that corresponds to the string constant pool array.
[0093] The offset values in the offset array are used to indicate the storage location of the string corresponding to the offset value in the string constant pool array.
[0094] In this embodiment of the disclosure, the target layout file includes an offset array corresponding to the string constant pool array, used to specify the storage location of each string in the string constant pool array. The offset values in the offset array have a one-to-one correspondence with the strings in the string constant pool array, and each offset value indicates the storage location of the corresponding string.
[0095] like Figure 5 As shown, this is a schematic diagram of the content of another layout file provided in an embodiment of this disclosure. In this layout, part ② includes an offset array stringoffsets[8] corresponding to the string constant pool array. stringoffsets[8] includes 8 offset values, each of which corresponds to a string in the string constant pool array.
[0096] S406: In the offset array, determine the offset values corresponding to the empty strings in the string constant pool array, and determine the target offset value from the offset values corresponding to the empty strings.
[0097] In this embodiment of the disclosure, after optimization of the target layout file in steps S401-S404, the string constant pool array includes multiple empty strings, such as... Figure 5 The examples shown are ① and ③. To further optimize the target layout file, the empty strings in parts ① and ③ can be merged into a single empty string.
[0098] In practical applications, the offset values corresponding to the empty strings in the string constant pool array are determined in the offset array, and the target offset value is determined from the offset values corresponding to each empty string.
[0099] In one alternative implementation, after determining the offset values corresponding to the empty strings in the string constant pool array in the offset array, the offset value corresponding to the first empty string is determined as the target offset value.
[0100] S407: Modify the offset values in the offset array that correspond to the empty string to the target offset value.
[0101] In this embodiment of the disclosure, after determining the target offset value, the offset values corresponding to each empty string in the offset array are modified to the target offset value. That is, the offset values corresponding to each empty string in the offset array are all pointed to the same storage location of the empty string, i.e., the target offset value, thereby freeing up the storage space of other empty strings.
[0102] In one optional implementation, the offset values corresponding to each empty string in the offset array are all set to the storage location of the first empty string. For example... Figure 5 As shown, the first to fifth offset values, the seventh and eighth offset values in the offset array are all pointed to the position of the first offset value in the offset array, thereby merging multiple empty strings.
[0103] Alternatively, if you simply replace the strings in the string constant pool array that have the same name as the target string with empty strings, you can further optimize the layout file based on the above method of merging empty strings. The specific implementation method will not be elaborated here.
[0104] In the layout file processing method provided in this embodiment, under the premise of optimizing the replacement of some strings in the string constant pool array with empty strings, multiple empty strings are further directed to the same storage location of the empty string, thereby releasing the storage space of some empty strings and further reducing the size of the APK package.
[0105] Based on the same inventive concept as the above-described method embodiments, this disclosure also provides a layout file processing apparatus, with reference to... Figure 6 This is a schematic diagram of a layout file processing apparatus provided in an embodiment of the present disclosure. The apparatus includes:
[0106] The first determining module 601 is used to determine the string constant pool array and the attribute value resMap array in the target layout file;
[0107] The second determining module 602 is used to determine the string in the resMap array as the target string;
[0108] The first replacement module 603 is used to replace the string with the same name as the target string in the string constant pool array with an empty string.
[0109] In one optional embodiment, the apparatus further includes:
[0110] The second replacement module is used to replace the namespace string in the string constant pool array with an empty string.
[0111] In one optional embodiment, the apparatus further includes:
[0112] The third determining module is used to determine the namespace nodes in the target layout file;
[0113] The first acquisition module is used to acquire the namespace name and namespace value in the namespace node;
[0114] The fourth determining module is used to determine the namespace string in the string constant pool array based on the namespace name and the namespace value.
[0115] In one optional embodiment, the apparatus further includes:
[0116] The fifth determining module is used to determine the offset array in the target layout file corresponding to the string constant pool array; wherein, the offset value in the offset array is used to indicate the storage location of the string corresponding to the offset value in the string constant pool array;
[0117] The sixth determining module is used to determine the offset values corresponding to the empty strings in the string constant pool array in the offset array, and to determine the target offset value from the offset values corresponding to the empty strings.
[0118] The modification module is used to modify the offset values in the offset array that correspond to the empty string to the target offset value.
[0119] In one optional implementation, the target offset value includes the offset value corresponding to the first empty string in the empty string.
[0120] In one optional implementation, the target layout file is any layout file in the Android application package (APK) to be optimized, and the layout file is a binary file used to describe the interface display content in the APK to be optimized; the apparatus further includes:
[0121] The generation module is used to generate the optimized APK corresponding to the APK to be optimized based on each of the replaced layout files corresponding to each layout file in the APK to be optimized.
[0122] In the layout file processing apparatus provided in this embodiment, firstly, the string constant pool array and the attribute value resMap array in the target layout file are determined. Then, the strings in the resMap array are identified as target strings. Subsequently, strings in the string constant pool array with the same name as the target string are replaced with empty strings. It can be seen that this embodiment reduces the package size of the APK to which the target layout file belongs by replacing some strings in the string constant pool array of the target layout file with empty strings.
[0123] In addition, while optimizing the strings in the string constant pool array that are the same as those in the resMap array, the namespace strings in the string constant pool array can also be optimized, further reducing the size of the APK package.
[0124] In addition, based on the optimization of replacing some strings in the string constant pool array with empty strings, multiple empty strings are further directed to the same storage location of the empty string, which releases some storage space for the empty strings and further reduces the size of the APK package.
[0125] In addition to the methods and apparatus described above, this disclosure also provides a computer-readable storage medium storing instructions that, when executed on a terminal device, cause the terminal device to implement the layout file processing method described in this disclosure.
[0126] This disclosure also provides a computer program product, which includes a computer program / instructions that, when executed by a processor, implement the layout file processing method described in this disclosure.
[0127] In addition, this disclosure also provides a layout file processing device, see [link to relevant documentation]. Figure 7 As shown, it may include:
[0128] The device includes a processor 701, a memory 702, an input device 703, and an output device 704. The number of processors 701 in the layout file processing device can be one or more. Figure 7 Taking a processor as an example. In some embodiments of this disclosure, the processor 701, memory 702, input device 703, and output device 704 can be connected via a bus or other means, wherein, Figure 7 Taking the example of a connection between China and Israel via a bus.
[0129] The memory 702 can be used to store software programs and modules. The processor 701 executes various functional applications and data processing of the layout file processing device by running the software programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function, etc. In addition, the memory 702 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device. The input device 703 can be used to receive input digital or character information, and to generate signal inputs related to user settings and function control of the layout file processing device.
[0130] Specifically in this embodiment, the processor 701 loads the executable files corresponding to the processes of one or more applications into the memory 702 according to the following instructions, and the processor 701 runs the applications stored in the memory 702, thereby realizing the various functions of the above-mentioned layout file processing device.
[0131] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0132] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method of processing a layout file, characterized by, The method comprises: determining a string constant pool array and a resMap array of attribute values in a target layout file, the target layout file being any layout file in a to-be-optimized Android application package APK, the layout file being a binary file used to describe interface display content in the to-be-optimized APK, and the resMap array being used to store attributes for implementing user interface display in the to-be-optimized APK and integer id values corresponding to the attributes; determining a target string from a string in the resMap array; replacing a string with the same name as the target string in the string constant pool array with an empty string to obtain a replaced layout file corresponding to the target layout file; generating an optimized APK corresponding to the to-be-optimized APK based on each replaced layout file after obtaining a replaced layout file corresponding to each layout file in the to-be-optimized APK.
2. The method of claim 1, wherein, The method further comprises: replacing a namespace string in the string constant pool array with an empty string.
3. The method of claim 2, wherein, Before the step of replacing the namespace string in the string constant pool array with an empty string, the method further comprises: determining a namespace node in the target layout file; obtaining a namespace name and a namespace value in the namespace node; determining a namespace string in the string constant pool array based on the namespace name and the namespace value.
4. The method according to any one of claims 1 to 3, characterized in that, The method further comprises: determining an offset array corresponding to the string constant pool array in the target layout file; wherein an offset value in the offset array is used to indicate a storage location of a string in the string constant pool array corresponding to the offset value; determining an offset value corresponding to an empty string in the string constant pool array in the offset array, and determining a target offset value from the offset value corresponding to the empty string; modifying the offset value corresponding to the empty string in the offset array to the target offset value.
5. The method of claim 4, wherein, The target offset value comprises an offset value corresponding to a first empty string in the empty string.
6. An apparatus for processing a layout file, characterized by: The apparatus comprises: a first determining module configured to determine a string constant pool array and a resMap array of attribute values in a target layout file, the target layout file being any layout file in a to-be-optimized Android application package APK, the layout file being a binary file used to describe interface display content in the to-be-optimized APK, and the resMap array being used to store attributes for implementing user interface display in the to-be-optimized APK and integer id values corresponding to the attributes; a second determining module configured to determine a target string from a string in the resMap array; a first replacing module configured to replace a string with the same name as the target string in the string constant pool array with an empty string; a generating module configured to generate an optimized APK corresponding to the to-be-optimized APK based on each replaced layout file after obtaining a replaced layout file corresponding to each layout file in the to-be-optimized APK.
7. A computer readable storage medium characterized in that, The computer readable storage medium stores instructions, and when the instructions run on the terminal device, the terminal device implements the method in any one of claims 1-5.
8. An electronic device, comprising: comprising: a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and when the processor executes the computer program, the method in any one of claims 1-5 is implemented.
9. A computer program product, characterised in that, The computer program product comprises computer programs / instructions, and when the computer programs / instructions are executed by the processor, the method in any one of claims 1-5 is implemented.
Citation Information
Patent Citations
Installation package packaging method, system and equipment and storage medium
CN109857455A
Interface layout method and device for Android application
CN110442419A