Disclosure of Invention
The embodiment of the application provides a resource processing method, device and equipment of an application program and a storage medium, so as to achieve the purpose of improving the resource processing efficiency of the application program.
In a first aspect, an embodiment of the present application provides a resource processing method for an application program, including:
after the resource merging task of the application program is finished, searching and deleting the target resource under the first specified storage path of the resource merging task;
replacing the call to the target resource in an extensible markup language (XML) file of the application program with the call to the specified resource;
after the resource processing task of the application program is finished, searching a resource identifier (resID) of the specified resource in an R file of the application program, and assigning a value to the member variable of the target resource in the R file by using the resource identifier of the specified resource;
and replacing the call to the target resource in the bytecode file (class file) of the application program with the call to the specified resource.
The method provided by the embodiment of the application is realized in the packaging process of the application, the characteristic that all resources of the application are collected to the first appointed storage path by using the resource merging task is utilized, and after the resource merging task is finished, the target resource is searched and deleted in the first appointed storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The resource processing method provided by the embodiment of the application can realize the processing of the target resource and does not influence the compiling and running of the application program. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
If the method provided by the embodiment of the present application is used for resource deduplication of an application program, the implementation manner of searching and deleting the target resource under the first specified storage path of the resource merging task may be: searching repeated resources under a first specified storage path of the resource merging task; and performing duplicate removal processing on the searched repeated resources, wherein the resources reserved through the duplicate removal processing are designated resources, and the resources deleted through the duplicate removal processing are target resources.
And if the resources of the application program need to be subjected to duplicate removal operation, searching for duplicate resources under the first specified storage path. Because all resources of the application program are saved under the first appointed storage path, repeated resources searched under the first appointed storage path can be comprehensively and accurately searched, and the condition of missing search is avoided.
On this basis, the above-mentioned searching for the duplicate resource under the first specified storage path of the resource merging task may be implemented in the following manner: respectively calculating hash values for each resource under a first specified storage path of the resource merging task by using a preset information digest algorithm; and searching for repeated resources according to the hash value of each resource, wherein the resources with the same hash value are the repeated resources.
The predetermined message digest algorithm may be an MD5 algorithm or a hash algorithm.
For the repeated resources, the hash values calculated by using the information summarization algorithm are the same, so that the repeated resources can be quickly determined by using the information summarization algorithm.
On the basis of any method embodiment, the resource processing task of the application program can be executed after the call of the target resource in the XML file of the application program is replaced by the call of the specified resource; and after the resource identifier of the specified resource is used for assigning the value for the member variable of the target resource in the R file, replacing the calling of the target resource in the byte code file of the application program with the calling of the specified resource.
Specifically, a Hook function can be used to Hook a resource merging task and a resource processing function, after the resource merging task is finished, the steps of searching and deleting the target resource and modifying the XML file are skipped to, after the XML file is modified, the original packaging process is returned to, the resource processing is continued, and after the resource processing is finished, the steps of modifying the R file and the CLASS file are skipped to.
Through the time sequence limitation, the smooth proceeding of the packaging process can be ensured, and the unstable packaging process caused by the disordered time sequence is avoided.
On this basis, before the resource identifier of the specified resource is used for assigning the value to the member variable of the target resource in the R file, the member variable of the target resource is also added in the R file.
If the processing is performed according to the time sequence, the target resource is deleted first, and then the R file is generated, so that the R file does not include the member variable of the target resource, and the member variable of the target resource is added before the member variable of the target resource in the R file is assigned.
On the basis of any of the above method embodiments, the above replacing the call to the target resource in the XML file of the application program with the call to the specified resource may be implemented in the following manner: searching for the call of the target resource under a second specified storage path of the extensible markup language file of the application program; the call to the target resource is replaced with a call to the specified resource.
The inventor finds that, in the process of implementing the present invention, for a specific type of resource, for example, a picture resource, a path that appears (is called) in an XML file is regularly followed, so that a path (a second specified storage path) corresponding to a target resource is predetermined, and when the XML file is modified, the calling of the target resource is searched only under the second specified storage path, instead of searching under all paths of the XML file, so that the searching efficiency is improved, and the searching time is shortened.
In a second aspect, an embodiment of the present application provides an apparatus for processing resources of an application, where the apparatus runs in a packaging process of the application, and includes:
the target resource deleting module is used for searching and deleting the target resource under the first specified storage path of the resource merging task after the resource merging task of the application program is finished;
the XML file modification module is used for replacing the calling of the target resource in the XML file of the application program with the calling of the specified resource;
the R file modification module is used for searching the resource identifier of the specified resource in the R file of the application program after the resource processing task of the application program is finished, and assigning a value to the member variable of the target resource in the R file by using the resource identifier of the specified resource;
and the bytecode file modification module is used for replacing the calling of the target resource in the bytecode file of the application program with the calling of the specified resource.
The device provided by the embodiment of the application runs in the packaging process of the application, and the resource merging task is utilized to collect all resources of the application to the characteristic of the first appointed storage path, and after the resource merging task is finished, the target resource is searched and deleted in the first appointed storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The resource processing device provided by the embodiment of the application can realize the processing of the target resource, and does not influence the compiling and normal operation of the application program. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
If the apparatus provided in the embodiment of the present application is used to perform resource deduplication on an application, the target resource deletion module may be specifically configured to: searching repeated resources under a first specified storage path of the resource merging task; and performing duplicate removal processing on the searched repeated resources, wherein the resources reserved through the duplicate removal processing are designated resources, and the resources deleted through the duplicate removal processing are target resources.
And if the resources of the application program need to be subjected to duplicate removal operation, searching for duplicate resources under the first specified storage path. Because all resources of the application program are saved under the first appointed storage path, repeated resources searched under the first appointed storage path can be comprehensively and accurately searched, and the condition of missing search is avoided.
On this basis, the above-mentioned searching for the duplicate resource under the first specified storage path of the resource merging task may be implemented in the following manner: respectively calculating hash values for each resource under a first specified storage path of the resource merging task by using a preset information digest algorithm; and searching for repeated resources according to the hash value of each resource, wherein the resources with the same hash value are the repeated resources.
The predetermined message digest algorithm may be an MD5 algorithm or a hash algorithm.
For the repeated resources, the hash values calculated by using the information summarization algorithm are the same, so that the repeated resources can be quickly determined by using the information summarization algorithm.
On the basis of any device embodiment, the resource processing task of the application program can be executed after the call of the target resource in the XML file of the application program is replaced by the call of the specified resource; and after the resource identifier of the specified resource is used for assigning the value for the member variable of the target resource in the R file, replacing the calling of the target resource in the byte code file of the application program with the calling of the specified resource.
Specifically, a Hook function can be used to Hook a resource merging task and a resource processing function, after the resource merging task is finished, the steps of searching and deleting the target resource and modifying the XML file are skipped to, after the XML file is modified, the original packaging process is returned to, the resource processing is continued, and after the resource processing is finished, the steps of modifying the R file and the CLASS file are skipped to.
Through the time sequence limitation, the smooth proceeding of the packaging process can be ensured, and the unstable packaging process caused by the disordered time sequence is avoided.
On this basis, before the resource identifier of the specified resource is used for assigning the value to the member variable of the target resource in the R file, the member variable of the target resource is also added in the R file.
If the processing is performed according to the time sequence, the target resource is deleted first, and then the R file is generated, so that the R file does not include the member variable of the target resource, and the member variable of the target resource is added before the member variable of the target resource in the R file is assigned.
On the basis of any of the above embodiments of the apparatus, the XML file modification module is specifically configured to: searching for the call of the target resource under a second specified storage path of the extensible markup language file of the application program; the call to the target resource is replaced with a call to the specified resource.
The inventor finds that, in the process of implementing the present invention, for a specific type of resource, for example, a picture resource, a path that appears (is called) in an XML file is regularly followed, so that a path (a second specified storage path) corresponding to a target resource is predetermined, and when the XML file is modified, the calling of the target resource is searched only under the second specified storage path, instead of searching under all paths of the XML file, so that the searching efficiency is improved, and the searching time is shortened.
In a third aspect, an embodiment of the present application further provides a computer device, including a processor and a memory;
the memory is used for storing programs for executing the methods of the various method embodiments; the processor is configured to execute programs stored in the memory.
According to the computer equipment provided by the embodiment of the application, the characteristic that all resources of the application program are collected to the first appointed storage path by the resource merging task is utilized, and after the resource merging task is finished, the target resources are searched and deleted in the first appointed storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The computer equipment provided by the embodiment of the application can realize the processing of the target resource, and does not influence the compiling and normal operation of the application program. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
In a fourth aspect, this application further provides a computer-readable storage medium storing a program for executing the method described in each embodiment of the first aspect.
The computer-readable storage medium provided in the embodiment of the present application utilizes the feature that the resource merging task collects all resources of the application program to the first specified storage path, and after the resource merging task is finished, searches for and deletes the target resource in the first specified storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The program stored in the computer-readable storage medium provided by the embodiment of the application can realize the processing of the target resource, and the compiling and normal operation of the application program are not influenced. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
Detailed Description
In order to better understand the technical solutions described above, the technical solutions of the embodiments of the present application are described in detail below with reference to the drawings and the specific embodiments, and it should be understood that the specific features of the embodiments and the embodiments of the present application are detailed descriptions of the technical solutions of the embodiments of the present application, and are not limitations of the technical solutions of the present application, and the technical features of the embodiments and the embodiments of the present application may be combined with each other without conflict.
The embodiment of the invention provides a resource processing method for an application program, which is used for processing a target resource in the packaging process of the application program, and can be but is not limited to carrying out duplicate removal processing on repeated resources, carrying out resource replacement processing and the like. The method provided by the embodiment of the invention is suitable for the application program of the android platform or the application program of other operating system platforms supporting the following processing procedures. As shown in fig. 1, the method comprises the steps of:
step 101, after the resource merging task of the application program is finished, searching and deleting the target resource under the first specified storage path of the resource merging task.
Taking the android platform as an example, the resource merging task is mergeResource. After the mergeResource is finished, all resources (including the remote dependent aar) of the application will be closed under intermedia/res/merger. Therefore, the intermedia/res/merge is the first designated storage path of the resource merging task.
And 102, replacing the call to the target resource in the XML file of the application program with the call to the specified resource.
The call to the resource in the XML file appears as a call to the resource name of the resource. Therefore, in step 102, replacing the call to the target resource with the call to the specified resource means replacing the resource name of the called target resource with the resource name of the specified resource.
And 103, after the resource processing task of the application program is finished, searching the resID of the specified resource in the R file of the application program, and assigning a value to the member variable of the target resource in the R file by using the resID of the specified resource.
And assigning the member variable of the target resource by using the resID of the specified resource, namely assigning the member variable of the target resource as the resID of the specified resource.
Taking the android platform as an example, the resource processing process is processResource. After processResource is finished, resids of all resources of the application are determined, and an R file (r.java) of the application is also generated.
And 104, replacing the call to the target resource in the CLASS file of the application program with the call to the specified resource.
In the CLASS file of the application program, the call to the resource is represented as a call to the resID of the resource, and therefore, the call to the target resource is replaced by a call to the specified resource, specifically, the resID of the called target resource is replaced by the resID of the specified resource.
The method provided by the embodiment of the application is realized in the packaging process of the application, the characteristic that all resources of the application are collected to the first appointed storage path by using the resource merging task is utilized, and after the resource merging task is finished, the target resource is searched and deleted in the first appointed storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The resource processing method provided by the embodiment of the application can realize the processing of the target resource, and does not influence the compiling and normal operation of the application program. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
If the method provided by the embodiment of the present application is used for resource deduplication of an application program, the implementation manner of searching and deleting the target resource under the first specified storage path of the resource merging task may be: searching repeated resources under a first specified storage path of the resource merging task; and performing duplicate removal processing on the searched repeated resources, wherein the resources reserved through the duplicate removal processing are designated resources, and the resources deleted through the duplicate removal processing are target resources.
If the pictures 1, 2 and 3 are found to be duplicated under the first specified storage path, the pictures 1, 2 and 3 are a group of repeated resources, the group of repeated resources are subjected to deduplication processing, the picture 1 which is found first is reserved as a specified resource, and the pictures 2 and 3 are deleted.
In practical applications, the first discovered resource is usually reserved as the designated resource. Of course, after all resources are traversed, resources can be designated from the repeated resources according to a predetermined rule for reservation.
And if the resources of the application program need to be subjected to duplicate removal operation, searching for duplicate resources under the first specified storage path. Because all resources of the application program are saved under the first appointed storage path, repeated resources searched under the first appointed storage path can be comprehensively and accurately searched, and the condition of missing search is avoided.
On this basis, the above-mentioned searching for the duplicate resource under the first specified storage path of the resource merging task may be implemented in the following manner: respectively calculating hash values for each resource under a first specified storage path of the resource merging task by using a preset information digest algorithm; and searching for repeated resources according to the hash value of each resource, wherein the resources with the same hash value are the repeated resources.
The predetermined message digest algorithm may be an MD5 algorithm, a hash algorithm, or another message digest algorithm, which is not limited in the embodiment of the present invention.
For the repeated resources, the hash values calculated by using the information summarization algorithm are the same, so that the repeated resources can be quickly determined by using the information summarization algorithm.
It should be noted that the method provided by the embodiment of the present invention may be used not only for resource deduplication, but also for other resource processing operations. For example, resource replacement, deletion, and the like are performed. If the resource replacement, deletion and other operations are carried out, the resource name of the resource to be replaced or deleted is determined in advance, the resource name of each resource under the first specified storage path is matched with the resource name of the resource to be replaced or deleted, and the target resource is searched and deleted in the mode.
Even if the resource is deleted, the XML file, the R file and the CLASS file need to be modified subsequently, so that errors in the compiling process of the application program are avoided. In this case, the designated resource is a predetermined resource, and the embodiment of the present invention does not limit the resource, and in practical application, the designated resource is determined as needed.
On the basis of any method embodiment, the resource processing task of the application program can be executed after the call of the target resource in the XML file of the application program is replaced by the call of the specified resource; and after the resource identifier of the specified resource is used for assigning the value for the member variable of the target resource in the R file, replacing the calling of the target resource in the byte code file of the application program with the calling of the specified resource.
Specifically, a Hook function can be used to Hook a resource merging task and a resource processing function, after the resource merging task is finished, the steps of searching and deleting the target resource and modifying the XML file are skipped to, after the XML file is modified, the original packaging process is returned to, the resource processing is continued, and after the resource processing is finished, the steps of modifying the R file and the CLASS file are skipped to.
Through the time sequence limitation, the smooth proceeding of the packaging process can be ensured, and the unstable packaging process caused by the disordered time sequence is avoided.
On this basis, before the resource identifier of the specified resource is used for assigning the value to the member variable of the target resource in the R file, the member variable of the target resource is also added in the R file.
If the processing is performed according to the time sequence, the target resource is deleted first, and then the R file is generated, so that the R file does not include the member variable of the target resource, and the member variable of the target resource is added before the member variable of the target resource in the R file is assigned.
Of course, the embodiment of the present invention may not be performed according to the above timing sequence, for example, after the resource processing task is completed, the target resource may be searched and deleted under the first specified storage path of the resource merging task. In this case, since the R file is already generated before the target resource is deleted, the member variables of the target resource exist in the R file, and then the member variables of the target resource need to be re-assigned.
On the basis of any of the above method embodiments, the above replacing the call to the target resource in the XML file of the application program with the call to the specified resource may be implemented in the following manner: searching for the call of the target resource under a second specified storage path of the extensible markup language file of the application program; the call to the target resource is replaced with a call to the specified resource.
The inventor finds that, in the process of implementing the present invention, for a specific type of resource, for example, a picture resource, a path that appears (is called) in an XML file is regularly followed, so that a path (a second specified storage path) corresponding to a target resource is predetermined, and when the XML file is modified, the calling of the target resource is searched only under the second specified storage path, instead of searching under all paths of the XML file, so that the searching efficiency is improved, and the searching time is shortened.
Taking the picture resource as an example, in the XML file, invoking the second specified storage path of the picture resource includes: layout/, draw able/, values-
The method provided by the embodiment of the invention can be realized in the packaging process of the application program by adding the resource processing packaging plug-in, and the packaging process comprising the method is described in detail by taking the duplication elimination of the picture resource of the application program of the android platform as an example.
In this embodiment, two key tasks in the plug-in hook packaging process for performing duplicate removal of picture resources are: a mergeResource (resource merge) task and a processResource (resource process) task, and a transformask (morph task) is newly added.
During application compilation, the mergeResource task is first executed. After the mergeResource task is finished, all resources of the application (including the remote dependent aar) will be closed under intermedia/res/merged.
And respectively calculating the MD5 value of the picture for all picture resources under the mediatitles/res/merge.
For the picture resources with the same MD5 value, only one picture is reserved, and the rest pictures are deleted. In this embodiment, the reserved picture resource is referred to as a host, and the deleted picture resource is referred to as a delete.
And replacing the resource name of the deleted picture resource called in the XML file with the resource name of the reserved picture resource. For example, @ drawable/delete is replaced with @ drawable/host.
The XML file has layout/, draw/, values/where the picture resource call (@ draw /) is likely to occur, so that the search and replacement can be performed only under these storage paths.
After the modification of the XML file is completed, the processResource task is executed. After the processResource task is finished, the resids of all resources of the application program are determined, and R.java is also generated.
And aiming at the generated R.java, performing the following treatment:
and finding out the resId of the reserved picture resource, supplementing the member variable of the deleted picture resource, and assigning the resId as the reserved picture resource.
The effect of this step is obvious, java occurs after processResource, java files under the application already use the deleted picture resources, and if the member variables of java files are not supplemented, the application compiling failure is caused.
By depending on whether the references of the resources in the class file in the introduced aar or the references of the deleted picture resources, errors which cannot be found by the resources tend to occur at runtime, so that the picture resources deleted in the class file need to be directly replaced by the resId of the reserved picture resources, namely, transform task, at the time of compiling.
And finishing packaging.
Through the processing procedure, repeated picture resources in the application program APK are automatically removed in the packaging process.
And in the packaging process, the image resources are removed from weight, the development stage is not sensed, and the resources in the aar can be processed.
Based on the same inventive concept as the method, an embodiment of the present application provides an apparatus for processing resources of an application, where the apparatus operates in a packaging process of the application, as shown in fig. 2, and includes:
the target resource deleting module 201 is configured to, after the resource merging task of the application is finished, search and delete a target resource under a first specified storage path of the resource merging task;
the XML file modification module 202 is used for replacing the calling of the target resource in the XML file of the application program with the calling of the specified resource;
the R file modification module 203 is configured to, after the resource processing task of the application program is finished, search a resource identifier of the specified resource in the R file of the application program, and assign a value to a member variable of the target resource in the R file by using the resource identifier of the specified resource;
and the bytecode file modifying module 304 is configured to replace the call to the target resource in the bytecode file of the application program with a call to the specified resource.
The device provided by the embodiment of the application runs in the packaging process of the application, and the resource merging task is utilized to collect all resources of the application to the characteristic of the first appointed storage path, and after the resource merging task is finished, the target resource is searched and deleted in the first appointed storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The resource processing device provided by the embodiment of the application can realize the processing of the target resource, and does not influence the compiling and normal operation of the application program. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
If the apparatus provided in the embodiment of the present application is used to perform resource deduplication on an application, the target resource deletion module may be specifically configured to: searching repeated resources under a first specified storage path of the resource merging task; and performing duplicate removal processing on the searched repeated resources, wherein the resources reserved through the duplicate removal processing are designated resources, and the resources deleted through the duplicate removal processing are target resources.
And if the resources of the application program need to be subjected to duplicate removal operation, searching for duplicate resources under the first specified storage path. Because all resources of the application program are saved under the first appointed storage path, repeated resources searched under the first appointed storage path can be comprehensively and accurately searched, and the condition of missing search is avoided.
On this basis, the above-mentioned searching for the duplicate resource under the first specified storage path of the resource merging task may be implemented in the following manner: respectively calculating hash values for each resource under a first specified storage path of the resource merging task by using a preset information digest algorithm; and searching for repeated resources according to the hash value of each resource, wherein the resources with the same hash value are the repeated resources.
The predetermined message digest algorithm may be an MD5 algorithm or a hash algorithm.
For the repeated resources, the hash values calculated by using the information summarization algorithm are the same, so that the repeated resources can be quickly determined by using the information summarization algorithm.
On the basis of any device embodiment, the resource processing task of the application program can be executed after the call of the target resource in the XML file of the application program is replaced by the call of the specified resource; and after the resource identifier of the specified resource is used for assigning the value for the member variable of the target resource in the R file, replacing the calling of the target resource in the byte code file of the application program with the calling of the specified resource.
Specifically, a Hook function can be used to Hook a resource merging task and a resource processing function, after the resource merging task is finished, the steps of searching and deleting the target resource and modifying the XML file are skipped to, after the XML file is modified, the original packaging process is returned to, the resource processing is continued, and after the resource processing is finished, the steps of modifying the R file and the CLASS file are skipped to.
Through the time sequence limitation, the smooth proceeding of the packaging process can be ensured, and the unstable packaging process caused by the disordered time sequence is avoided.
On this basis, before the resource identifier of the specified resource is used for assigning the value to the member variable of the target resource in the R file, the member variable of the target resource is also added in the R file.
If the processing is performed according to the time sequence, the target resource is deleted first, and then the R file is generated, so that the R file does not include the member variable of the target resource, and the member variable of the target resource is added before the member variable of the target resource in the R file is assigned.
On the basis of any of the above embodiments of the apparatus, the XML file modification module is specifically configured to: searching for the call of the target resource under a second specified storage path of the extensible markup language file of the application program; the call to the target resource is replaced with a call to the specified resource.
The inventor finds that, in the process of implementing the present invention, for a specific type of resource, for example, a picture resource, a path that appears (is called) in an XML file is regularly followed, so that a path (a second specified storage path) corresponding to a target resource is predetermined, and when the XML file is modified, the calling of the target resource is searched only under the second specified storage path, instead of searching under all paths of the XML file, so that the searching efficiency is improved, and the searching time is shortened.
Based on the same inventive concept as the method, the embodiment of the application provides computer equipment, which comprises a processor and a memory; the memory is used for storing programs for executing the methods of the various method embodiments; the processor is configured to execute programs stored in the memory.
According to the computer equipment provided by the embodiment of the application, the characteristic that all resources of the application program are collected to the first appointed storage path by the resource merging task is utilized, and after the resource merging task is finished, the target resources are searched and deleted in the first appointed storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The computer equipment provided by the embodiment of the application can realize the processing of the target resource, and does not influence the compiling and normal operation of the application program. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
Fig. 3 is a block diagram illustrating a partial structure of a computer device related to an embodiment of a method provided by the embodiment of the present application. Referring to fig. 3, the computer apparatus includes:
the power supply is logically connected with the central processing unit through the power supply management system, so that the functions of managing charging, discharging, power consumption management and the like are realized through the power supply management system; the mainboard is used for providing an electric connection path among the components, each component is used for carrying out electric signal transmission through the mainboard, and each component is arranged on the mainboard in a plugging way, a welding way and the like; a central processing Unit (cpu), which mainly includes an Arithmetic Logic Unit (ALU), a Program Counter (PC), a register set, a Cache memory (Cache), and a Bus (Bus) interface for transmitting data, control, and status; the internal memory, the magnetic disk (i.e. the above-mentioned memory storing the program for executing the method described in each method embodiment), the input unit (including mouse, keyboard, touch panel, etc.), the display unit (including display and display card), and the network card exchange data with the central processing unit through the bus.
The program and the related data for executing the method according to the embodiments of the method are first read from the magnetic disk into the internal memory, and the central processing unit reads and loads the program from the internal memory.
Those skilled in the art will appreciate that the computer device configuration illustrated in FIG. 3 does not constitute a limitation of computer devices, and may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components.
Based on the same inventive concept as the method, embodiments of the present application provide a computer-readable storage medium storing a program for executing the method according to each embodiment of the first aspect.
The computer-readable storage medium provided in the embodiment of the present application utilizes the feature that the resource merging task collects all resources of the application program to the first specified storage path, and after the resource merging task is finished, searches for and deletes the target resource in the first specified storage path. If the R file and the bytecode file of the application call the target resource, deleting the target resource may cause the compiling failure of the application. In order to avoid the failure of the compiling of the application program caused by the deletion of the target resource, the XML file, the R file and the CLASS file of the application program need to be modified. The modification of the XML file modifies the call to the target resource to a call to the specified resource. Because the resource processing task generates the resource identifier for the resource of the application program, and the calling of the resource in the R file and the bytecode file is represented as the calling of the resource identifier for the resource, the resource identifier of the specified resource can be used as the member variable of the target resource for assignment in the R file after the resource processing task is finished, and the resource identifier of the specified resource is used for replacing the resource identifier of the called target resource in the bytecode file. Then, in the running process of the application program, if the target resource is called, the specified resource is actually called. The program stored in the computer-readable storage medium provided by the embodiment of the application can realize the processing of the target resource, and the compiling and normal operation of the application program are not influenced. The processing process can be automatically executed by a computer program, so that manual processing is avoided, and the processing efficiency is improved.
The description has been presented with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the description. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While preferred embodiments of the present specification have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all changes and modifications that fall within the scope of the specification.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present specification without departing from the spirit and scope of the specification. Thus, if such modifications and variations of the present specification fall within the scope of the claims of the present specification and their equivalents, the specification is intended to include such modifications and variations.