Resource file cleaning method and device, electronic equipment and readable medium

By repeatedly searching for resource identifiers and code identifiers in the project code, the problem of incomplete or accidental cleanup of resource files in the APP installation package was solved, thus optimizing the APP installation package.

CN114816450BActive Publication Date: 2026-01-16BEIJING CHENGSHI WANGLIN INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210333616.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2026-01-16
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

Existing technologies are prone to accidentally cleaning up useful resource files or failing to completely clean up useless resource files when cleaning up APP installation packages, resulting in a waste of storage space and download bandwidth.

Method used

By searching for resource identifiers in resource files and code identifiers in code files within the project code, useless resource files are identified. Multiple searches are conducted to ensure accuracy, and then useless resource files are cleaned up.

Benefits of technology

Accurately detect and clean up useless resource files in the APP installation package, reduce the size of the APP installation package, avoid accidentally cleaning up useful files, and optimize the APP installation package.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114816450B_ABST
    Figure CN114816450B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a resource file cleaning method and device, electronic equipment and readable medium, the method comprises: obtaining the project code and project resource package of application program; searching in the project code by using the resource identifier to obtain the first search result; if the first search result is that the target code file where the resource identifier is located is not the specified code file, searching in the project code by using the code identifier of the target code file to obtain the second search result; if the second search result is empty or the code identifier of the target code file is in the specified code file, ending the search of the resource identifier, and determining the resource identifier corresponding to the empty second search result as useless resource identifier, and determining the resource identifier corresponding to the code identifier of the target code file in the specified code file as useful resource identifier; cleaning the resource file corresponding to the useless resource identifier in the project resource package. Embodiments of the present application can reduce the size of APP installation package.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of Internet, in particular to a resource file cleaning method, a resource file cleaning device, an electronic device and a computer readable medium. BACKGROUND

[0002] With the rapid development of Internet technology, the update iteration speed of APP (Application) is getting faster and faster. The multiple version iterations of APP make the size of APP installation package increase. The oversized APP installation package occupies more storage space and consumes more download traffic. Therefore, it has become a problem to be solved for those skilled in the art to optimize the APP installation package.

[0003] In the prior art, the optimization method of the APP installation package is to clean the useless resource files in the APP installation package. However, although the prior art can reduce the size of the APP installation package to a certain extent, there are problems of mis-cleaning useful resource files or incomplete cleaning of useless resource files. SUMMARY

[0004] Embodiments of the present application provide a resource file cleaning method, device, electronic device and computer readable storage medium to solve the problem of mis-cleaning useful resource files or incomplete cleaning of useless resource files in the APP installation package.

[0005] Embodiments of the present application disclose a resource file cleaning method, which comprises:

[0006] obtaining the project code and the project resource package of the application program; the code file in the project code file has a corresponding code identifier, and the resource file in the project resource package has a corresponding resource identifier;

[0007] searching in the project code using the resource identifier to obtain a first search result;

[0008] if the first search result is that the target code file where the resource identifier is located is not a specified code file, searching in the project code using the code identifier of the target code file to obtain a second search result;

[0009] if the second search result is empty or the code identifier of the target code file is in the specified code file, ending the search of the resource identifier, and determining the resource identifier corresponding to the empty second search result as a useless resource identifier, and determining the resource identifier corresponding to the code identifier of the target code file in the specified code file as a useful resource identifier;

[0010] Cleaning the resource file corresponding to the useless resource identifier in the project resource package.

[0011] Optionally, the resource identifier is obtained by:

[0012] Scanning a project directory of the project resource package to obtain a resource file path of the resource file.

[0013] Extracting the resource identifier of the resource file from the resource file path.

[0014] Optionally, the resource file path comprises a submission time when submitted to a system platform for managing the application program, and the searching in the project code by using the resource identifier to obtain the first search result comprises:

[0015] According to the time sequence of the submission time of the resource file, the searching in the project code by using the resource identifier is sequentially performed to obtain the first search result.

[0016] Optionally, after the searching in the project code by using the resource identifier to obtain the first search result, the method further comprises:

[0017] If the first search result is empty, the corresponding resource identifier is determined as a useless resource identifier.

[0018] Optionally, after the searching in the project code by using the resource identifier to obtain the first search result, the method further comprises:

[0019] If the first search result is that the target code file where the resource identifier is located is a specified code file, the corresponding resource identifier is determined as a useful resource identifier.

[0020] Optionally, after the searching in the project code by using the code identifier of the target code to obtain the second search result, the method further comprises:

[0021] If the second search result is that the code identifier of the target code file is not in the specified code file, the code file where the code identifier of the target code file is located is taken as a target code file, and the step of searching in the project code by using the code identifier of the target code file to obtain the second search result is returned to be executed.

[0022] Optionally, the specified code file is a non-interface design file, and the specified code file is a Java file or a Kotlin file.

[0023] Embodiments of the application also disclose a resource file cleaning device, which comprises:

[0024] The application further provides an application program useless resource identifier determining device, comprising: an acquisition module, used for acquiring project code and project resource package of an application program; code files in the project code file have corresponding code identifiers, and resource files in the project resource package have corresponding resource identifiers;

[0025] a first search module, used for searching in the project code by using the resource identifier to obtain a first search result;

[0026] a second search module, used for searching in the project code by using a code identifier of a target code file in which the resource identifier is located to obtain a second search result if the first search result is that the target code file is not a specified code file;

[0027] a determination module, used for ending the search of the resource identifier if the second search result is empty or the code identifier of the target code file is in a specified code file, and determining the resource identifier corresponding to the second search result being empty as a useless resource identifier and the resource identifier corresponding to the code identifier of the target code file being in the specified code file as a useful resource identifier;

[0028] a cleaning module, used for cleaning a resource file corresponding to the useless resource identifier in the project resource package.

[0029] Optionally, the device further comprises a resource identifier acquisition module, used for scanning a project directory of the project resource package to obtain a resource file path of a resource file, and extracting a resource identifier of the resource file from the resource file path.

[0030] Optionally, the resource file path comprises a submission time when the resource file is submitted to a system platform for managing the application program, and the first search module is used for searching in the project code by using the resource identifier in a time sequence of the submission time of the resource file to obtain a first search result.

[0031] Optionally, the device further comprises a useless resource identifier determination module, used for determining the resource identifier corresponding to the first search result being empty as a useless resource identifier.

[0032] Optionally, the device further comprises a useful resource identifier determination module, used for determining the resource identifier corresponding to the first search result as a useful resource identifier if the target code file in which the resource identifier is located is a specified code file.

[0033] Optionally, the apparatus further comprises a returning execution module configured to, if the second search result is that the code identifier of the target code file is not in the specified code file, return to execute the step of searching in the project code using the code identifier of the target code file to obtain a second search result, wherein the code file in which the code identifier of the target code file is located is taken as the target code file.

[0034] Optionally, the specified code file is a non-interface design file, and the specified code file is a Java file or a Kotlin file.

[0035] The embodiment of the application further discloses an electronic device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus.

[0036] The memory is used for storing a computer program.

[0037] The processor is used for executing the program stored on the memory, and realizes the method as described in the embodiment of the application.

[0038] The embodiment of the application further discloses one or more computer readable media, which store instructions, and when executed by one or more processors, make the processor execute the method as described in the embodiment of the application.

[0039] The embodiment of the application further discloses a computer program product, which is stored in a storage medium, and the computer program product is executed by at least one processor to realize the method as described in the embodiment of the application.

[0040] The embodiment of the application has the following advantages:

[0041] In the embodiment of the present application, the project code and the project resource package of an application program are acquired, a resource identifier of a resource file in the project resource package is searched in the project code to obtain a first search result, if the target code file where the resource identifier is located is not a specified code file, a code identifier of the target code file is searched in the project code to obtain a second search result, if the second search result is empty or the code identifier of the target code file is in the specified code file, the search of the resource identifier can be ended, the resource identifier corresponding to the second search result is determined as a useless resource identifier, and the resource identifier corresponding to the code identifier of the target code file in the specified code file is determined as a useful resource identifier, wherein the resource file corresponding to the useless resource identifier in the project resource package can be cleaned. The embodiment of the present application searches in the project code based on the resource identifier of the resource file and the code identifier of the code file where the resource file is located, thereby accurately and completely detecting the useless resource identifier corresponding to the useless resource file in the project code, and cleaning the useless resource file in the APP installation package on the basis of avoiding the useless resource file in the APP installation package, so as to reduce the size of the APP installation package. BRIEF DESCRIPTION OF DRAWINGS

[0042] Figure 1 is a step flow chart of a resource file cleaning method provided in the embodiment of the present application;

[0043] Figure 2 is a schematic diagram of a project code provided in the embodiment of the present application;

[0044] Figure 3 is a schematic diagram of a resource file path provided in the embodiment of the present application;

[0045] Figure 4 is a step flow chart of a resource file cleaning method provided in the embodiment of the present application;

[0046] Figure 5 is a structural block diagram of a resource file cleaning device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0047] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the present application will be further described in detail below with reference to the drawings and specific embodiments.

[0048] In the related art, the optimization method of the APP installation package can be using the Lint detection tool of the Android Studio (a commonly used code editing and compiling tool used by developers to develop applications of Android), the Lint detection tool is a code scanning tool provided by the Android Studio, and the static analysis of the code using the Lint detection tool can help the developer to find some quality problems in the code. Specifically, the Lint detection tool finds the useless resource files in the APP installation package through the command: lint--check unUsedResources, and then deletes the useless resource files manually or by using other tools.

[0049] However, limited by the Lint detection tool itself, there are the following defects: 1, the Lint detection tool cannot judge the resource files obtained through the reflection method of Android, which may cause the problem of false cleaning; 2, some resource files have reference relationship, but in fact the implementation logic of the project code, the resource file is a useless resource file, but the Lint detection tool cannot detect these resource files.

[0050] In view of the above problems, the embodiment of the application provides a resource file cleaning method, which can be used for packaging project code and project resource package to generate APP installation package, and the useless resource files are determined by searching the resource identifier of the resource file in the project code and whether the code file where the resource identifier is located is in the specified code file in the project code, and then the useless resource files in the project resource package can be cleaned, the useless resource files in the APP installation package can be cleaned on the basis of avoiding false cleaning of the useful resource files in the APP installation package, and the size of the APP installation package is reduced.

[0051] Reference Figure 1 , a step flowchart of a resource file cleaning method provided in the embodiment of the application is shown, which can specifically include the following steps:

[0052] Step 102, obtaining the project code and the project resource package of the application program; the code files in the project code file have corresponding code identifiers, and the resource files in the project resource package have corresponding resource identifiers.

[0053] The resource file cleaning method of the embodiment of the application is realized by a terminal device. The terminal device can be but is not limited to various personal computers, notebook computers, smart phones, tablet computers, robots, vehicle-mounted terminals, portable wearable devices and servers, and the server can be realized based on an independent server or a server cluster composed of multiple servers.

[0054] The project source code refers to the source code of the APP, and the project resource package refers to a collection of resource files used in the project code of the APP, including resource files required for implementing various functions of the APP.

[0055] The project code can include a plurality of code files, each code file having a corresponding code identifier, such as a scr, bin, and docs string; and the project resource package can include a plurality of resource files, each resource file having a corresponding resource identifier, such as a png, jpg, mp3, mp4, and image string. In a specific example, the format of the code file and the resource file can include an XML format.

[0056] In the embodiment of the application, the project code and the project resource package of the APP installation package can be acquired before the operator publishes the APP installation package to the application store or after the user downloads the APP installation package from the application store.

[0057] In step 104, the resource identifier is used to search the project code to obtain a first search result.

[0058] In step 106, if the first search result is that the target code file in which the resource identifier is located is not a specified code file, the code identifier of the target code file is used to search the project code to obtain a second search result.

[0059] In step 108, if the second search result is empty or the code identifier of the target code file is in the specified code file, the search for the resource identifier is ended, the resource identifier corresponding to the empty second search result is determined as a useless resource identifier, and the resource identifier corresponding to the code identifier of the target code file in the specified code file is determined as a useful resource identifier.

[0060] The code file can include an interface design file, which is used to specify the layout or style of the interface in the APP, such as displaying a resource file, such as a picture, at which position in the interface, and is usually in an XML format. The specified code file refers to a code file that is not an interface design file, and the specified code file can be a Java file or a Kotlin file, which is the development code of the APP and is very important and cannot be changed at will. If it is changed, problems such as APP crash and running error are likely to occur.

[0061] In a specific implementation, the resource identifier of the resource file can be referenced in a code file, such as an interface design file, a Java file, or a Kotlin file, and the code file can also be referenced by other code files. For example, assume that there is a resource identifier A, which can be referenced in a code file B, and the code file B can be referenced by a code file C. Therefore, in the embodiment of the application, in order to accurately and completely detect the useless resource files in the project code as much as possible, multiple rounds of searches can be required to determine whether some resource files are referenced. Of course, the number of searches is determined according to the search results, and can be one, two, or more times.

[0062] The resource identifier can include a useless resource identifier and a useful resource identifier. The useless resource identifier indicates that the corresponding resource file is a useless resource file, and if the useless resource file is deleted from the project resource package, the normal operation of the APP will not be affected. The useful resource identifier indicates that the corresponding resource file is a useful resource file, and if the useful resource file is deleted from the project resource package, the normal operation of the APP is likely to be affected.

[0063] In the embodiment of the application, the resource identifier is used to search in the project code. The search is performed in a case-sensitive and complete matching manner. If the first search result obtained by searching in the project code using the resource identifier is that the target code file in which the resource identifier is located is not a specified code file, that is, the resource identifier is not in a Java file or a Kotlin file, then a second search can be further performed in the project code according to the code identifier of the target code file in which the resource identifier is located. If the second search result obtained by searching in the project code using the code identifier of the target code file is empty, or the code identifier of the target code file is not in the specified code file, then the search for the resource identifier is ended, and the resource identifier corresponding to the empty second search result is determined as a useless resource identifier, and the resource identifier corresponding to the second search result in which the code identifier of the target code file is not in the specified code file is determined as a useless resource identifier.

[0064] Exemplarily, assuming that there is a resource identifier of a resource file: room1.png, if the first search result obtained by searching room1.png in the project code is that the target code file in which the resource identifier is located is not the specified code file, that is, room1.png is not in the Java file or the Kotlin file, if it is determined that the code identifier of the target code file in which room1.png is located is layout 8, then room1.png can be further searched in the project code by using layout 8 to obtain a second search result. If the second search result obtained by searching layout 8 in the project code is empty, the search for room1.png can be ended, and room1.png is determined as a useless resource identifier, or layout 8 is not in the specified code file, that is, layout 8 is not in the Java file or the Kotlin file, and the search for room1.png can also be ended, and room1.png is determined as a useless resource identifier.

[0065] Step 110: cleaning the resource file corresponding to the useless resource identifier in the project resource package.

[0066] In the embodiment of the application, the useless resource identifier is used to indicate that the corresponding resource file is a useless resource file and can be cleaned from the APP installation package, and the useful resource identifier is used to indicate that the corresponding resource file is a useful resource file and cannot be cleaned from the APP installation package. Therefore, if it is determined that there is a useless resource identifier, the resource file corresponding to the useless resource identifier in the project resource package is cleaned, so that the APP installation package generated based on the project code and the project resource package does not contain useless resource files, thereby reducing the size of the APP installation package and achieving optimization of the APP installation package.

[0067] As a specific example, the resource file cleaning process is integrated in the Gradle plug-in, and the resource identifier of the resource file to be detected is automatically collected by using a git command, and the reference detection of the resource identifier of the resource file, that is, whether the code file is referenced or the code file in which the resource identifier of the resource file is located is referenced by other code files, is performed.

[0068] In the above resource file cleaning method, the project code and the project resource package of an application program are acquired, a resource identifier of a resource file in the project resource package is used to search in the project code to obtain a first search result, if the target code file where the resource identifier is located is not a specified code file, a code identifier of the target code file is used to search in the project code to obtain a second search result, if the second search result is empty or the code identifier of the target code file is in the specified code file, the search for the resource identifier can be ended, and the resource identifier corresponding to the second search result being empty is determined as a useless resource identifier, and the resource identifier corresponding to the code identifier of the target code file being in the specified code file is determined as a useful resource identifier, wherein the resource file corresponding to the useless resource identifier in the project resource package can be cleaned. Based on the resource identifier of the resource file and the code identifier of the code file where the resource file is located, the project code is searched multiple times in the embodiment of the application, so that the useless resource identifier corresponding to the useless resource file in the project code is accurately and completely detected, the useless resource file in the APP installation package can be comprehensively cleaned on the basis of avoiding the useless resource file in the APP installation package being mistakenly cleaned, and the size of the APP installation package is reduced.

[0069] On the basis of the above embodiment, a variant embodiment of the above embodiment is provided, and it should be noted that, in order to make the description brief, only the differences from the above embodiment are described in the variant embodiment.

[0070] In an example embodiment, the resource identifier can be acquired in the following manner:

[0071] The project directory of the project resource package is scanned to obtain a resource file path of the resource file;

[0072] The resource identifier of the resource file is extracted from the resource file path.

[0073] In a specific implementation, the project code and the project resource package can be managed by Git. Specifically, Git is an open source distributed version control system, which is usually used to manage the version of the project code in the development of the project (APP) and has detailed commit logs.

[0074] In the embodiment of the application, the project directory of the project resource package is determined as a specified project directory, or the specific project directory of the project resource package is determined as a specified project directory, and then the following git command can be executed on the specified project directory:

[0075] while read file; do echo $(git log --pretty=format:%ad-n 1 --date=iso-local--$file) $file; done <<(git ls-tree -r --name-only HEAD)|sort -k1,1n

[0076] After the execution of the above git command, the resource file path of all resource files in the specified project directory can be scanned, and then the resource file path of the resource files in the project resource package is output based on the time sequence according to the commit time of the resource files committed to the Git. Exemplarily, refer to Figure 3 , which is a schematic diagram of a resource file path provided in an embodiment of the present application. Each row in the diagram represents a resource file path of a resource file, and the resource file paths are output in the time sequence from far to near according to the commit time.

[0077] After obtaining the resource file path, the resource identifier of the resource file can be further extracted from the resource file path. For example, refer to Figure 3 , Figure 3 The resource file path of the first row in the above table is 2015-01-18 12:59:36 +0800 drawable-hdpi / weather_boarder.9.png, and the resource identifier of the resource file can be extracted from the resource file path: weather_boarder.9.png.

[0078] In the above exemplary embodiment, by scanning the project directory of the project resource package, the resource file path of the resource file is obtained, and then the resource identifier of the resource file can be extracted from the resource file path, and the resource identifier of all resource files in the project directory of the project resource package is obtained, which is helpful for the complete detection of useless resource files in the APP installation package.

[0079] In an exemplary embodiment, the resource file path includes the commit time when the resource file is committed to the system platform for managing the application program, and the step 104 of searching the project code by using the resource identifier to obtain the first search result can include the following steps:

[0080] The resource identifier is used to search the project code in sequence to obtain the first search result according to the time sequence of the commit time of the resource file.

[0081] In the embodiment of the present application, the resource identifier is usually multiple, so the resource identifier is used to search in the project code in sequence. In order to ensure the search of the resource identifier in order, the resource identifier can be used to search in the project code in the time sequence of the submission time of the system platform managing the application program, that is, the submission time of the Git.

[0082] As a specific example, the resource identifier can be used to search in the project code in the time sequence of the submission time from far to near, or the resource identifier can be used to search in the project code in the time sequence of the submission time from near to far, and the embodiment of the present application does not need to be limited.

[0083] In actual application, with the update iteration of the APP, the submission time of the resource file will be more and more remote, and generally the more remote the submission time is, the higher the probability of uselessness of the resource identifier is. Therefore, in order to quickly clean up the useless resource file, the resource identifier can be used to search in the project code in the time sequence of the submission time from far to near.

[0084] In the above example embodiment, the resource identifier is used to search in the project code in the time sequence of the submission time, which can ensure the search in order.

[0085] In an example embodiment, after the step 104 of using the resource identifier to search in the project code to obtain the first search result, the method can further include the following steps:

[0086] If the first search result is empty, the corresponding resource identifier is determined as a useless resource identifier.

[0087] In the embodiment of the present application, the resource identifier is used to search in the project code, and the first search result can be obtained. If the first search result is empty, it indicates that the resource identifier is not referenced in the project code, so the resource identifier can be directly determined as a useless resource identifier and added to the deletable file list. Subsequently, after the traversal of all resource identifiers in the project code is completed, the useless resource identifier in the project resource package can be cleaned as a useless resource file according to the useless resource identifier in the deletable file list.

[0088] In the above example embodiment, if the search result of using the resource identifier to search in the project code is empty, it indicates that the resource identifier is not referenced in the project code, so the resource identifier can be directly determined as a useless resource identifier and cleaned from the project resource package. Of course, no other processing is needed for the resource identifier, which is beneficial to improve the cleaning efficiency of the useless resource file.

[0089] In an example embodiment, after the step 104, searching in the project code by using the resource identifier to obtain a first search result, the method can further include the following steps:

[0090] If the first search result is that the target code file where the resource identifier is located is a specified code file, the corresponding resource identifier is determined as a useful resource identifier.

[0091] In the embodiment of the application, searching in the project code by using the resource identifier can obtain a first search result. If the first search result is that the target code file where the resource identifier is located is a specified code file, for example, the target code file where the resource identifier is located is a Java file or a Kotlin file, since the specified code file is an important code file, if the resource file required by the specified code file is missing, problems such as APP crash and running error are likely to occur. Therefore, the resource identifier can be determined as a useful resource identifier, that is, the resource file corresponding to the resource identifier does not need to be cleaned up in the project resource package.

[0092] In the above example embodiment, if the search result of searching in the project code by using the resource identifier is that the target code file where the resource identifier is located is a specified code file, it indicates that the resource identifier needs to be referenced in the project code. Therefore, the resource identifier can be determined as a useful resource identifier, and cleaning up is not required, thereby avoiding the false cleaning up of useful resource files.

[0093] In an example embodiment, after the step 106, searching in the project code by using the code identifier of the target code to obtain a second search result, the method can further include the following steps:

[0094] If the second search result is that the code identifier of the target code file is not in the specified code file, the code file where the code identifier of the target code file is located is taken as the target code file, and the step of searching in the project code by using the code identifier of the target code file to obtain a second search result is executed again.

[0095] In the embodiment of the present application, the resource identifier is used to search in the project code, and the first search result can be obtained. If the target code file where the resource identifier is located is not the specified code file, for example, the target code file where the resource identifier is located is not the Java file or the Kotlin file, that is, the important code file in the project code, even if the resource file required for reference is missing, APP crash, running error and other problems are not easy to occur. Therefore, in order to clean up as much as possible the useless resource files in the project resource package, the code identifier of the target code file where the resource identifier is located is used to perform secondary search in the project code file, and the second search result is obtained. If the second search result is not empty and the code identifier of the target code file is not in the specified code file, it means that the target code file can be referenced by other code files. Therefore, the code file where the code identifier of the target code file is located can be used as a new target code file, and the code identifier of the target code file is used to continue to perform secondary search in the project code file, and the second search result is obtained. The search for the resource identifier is ended until the second search result is empty or the code identifier of the target code file is in the specified code file.

[0096] In the above exemplary embodiment, before the code identifier of the target code file is used to search in the project code and the second search result is empty or the code identifier of the target code file is in the specified code file, the search in the project code will continue to detect as accurately and completely as possible the useless resource identifier in the project code, so as to clean up as accurately and completely as possible the useless resource files in the project resource package.

[0097] In order for those skilled in the art to better understand the embodiments of the present application, the following will be described with a complete example. Referring to Figure 4 It is a step flow chart of a resource file cleaning provided by the embodiment of the present application, and the APP installation package project code and the project resource package are used, and the specific steps are as follows:

[0098] Step 402, specifying the project directory, executing the git command, and obtaining the time-ordered resource file name list; the resource file name list includes the resource identifier of the resource file;

[0099] Step 404, taking the resource identifier far in time;

[0100] Step 406, searching the resource identifier in the project code;

[0101] Step 408, whether there is a code file for reference; if yes, step 410 is executed, and if no, step 416 is executed;

[0102] Step 410, whether the search result is only non-designated code files; if yes, step 412 is executed, and if no, step 414 is executed;

[0103] Step 412, traversing the non-designated code files in the search result;

[0104] Step 414, excluding the resource identifier on the reference chain, and returning to step 404;

[0105] Step 416, adding the resource identifier to the deletable file list;

[0106] Step 418, deleting the useless resource files in the project resource package based on the deletable file list.

[0107] By applying the embodiments of the present application, the problem of possible incorrect cleaning or incomplete detection of useless resource files in the prior art is solved, and the useless resource files in the project code are detected as accurately and completely as possible, and cleaned, so that the optimization of the size of the APP installation package is realized.

[0108] It should be noted that, for the method embodiments, in order to simply describe, they are all expressed as a series of action combinations, but those skilled in the art should know that the embodiments of the present application are not limited by the action order described, because according to the embodiments of the present application, certain steps can be performed in other order or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions involved are not necessarily necessary for the embodiments of the present application.

[0109] Referring to Figure 5 , a structural block diagram of a resource file cleaning device provided in the embodiments of the present application is shown, which can specifically include the following modules:

[0110] The acquisition module 502 is configured to acquire the project code and the project resource package of an application program; the code files in the project code file have corresponding code identifiers, and the resource files in the project resource package have corresponding resource identifiers;

[0111] The first search module 504 is configured to search in the project code by using the resource identifier to obtain a first search result;

[0112] The second search module 506 is configured to, if the first search result is that the target code file where the resource identifier is located is not a designated code file, search in the project code by using the code identifier of the target code file to obtain a second search result;

[0113] The determining module 508 is configured to end the search of the resource identifier if the second search result is empty or the code identifier of the target code file is in the specified code file, and determine the resource identifier corresponding to the second search result as a useless resource identifier, and determine the resource identifier corresponding to the code identifier of the target code file as a useful resource identifier.

[0114] The cleaning module 510 is configured to clean the resource file corresponding to the useless resource identifier in the project resource package.

[0115] In an example embodiment, the apparatus can further include a resource identifier obtaining module configured to scan a project directory of the project resource package to obtain a resource file path of a resource file, and extract a resource identifier of the resource file from the resource file path.

[0116] In an example embodiment, the resource file path includes a submission time when the resource file is submitted to a system platform for managing the application program, and the first search module 504 is configured to search the resource identifier in the project code in a time sequence of the submission time of the resource file to obtain a first search result.

[0117] In an example embodiment, the apparatus can further include a useless resource identifier determining module configured to determine the resource identifier as a useless resource identifier if the first search result is empty.

[0118] In an example embodiment, the apparatus can further include a useful resource identifier determining module configured to determine the resource identifier as a useful resource identifier if the first search result is that the target code file in which the resource identifier is located is a specified code file.

[0119] In an example embodiment, the apparatus can further include a return execution module configured to, if the second search result is that the code identifier of the target code file is not in the specified code file, take the code file in which the code identifier of the target code file is located as a target code file, and return to execute the step of searching the target code file in the project code to obtain a second search result.

[0120] In an example embodiment, the specified code file can be a non-interface design file, and the specified code file is a Java file or a Kotlin file.

[0121] For the apparatus embodiment, it is basically similar to the method embodiment, and thus the description is relatively simple, and the related parts refer to the part of the method embodiment.

[0122] Preferably, the embodiment of the present application further provides an electronic device, comprising a processor, a memory, a computer program stored in the memory and executable in the processor, the computer program is executed by the processor to realize the processes of the above-mentioned resource file cleaning method embodiments and achieve the same technical effects, and details are not repeated here to avoid repetition.

[0123] The embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program, the computer program is executed by the processor to realize the processes of the above-mentioned resource file cleaning method embodiments and achieve the same technical effects, and details are not repeated here to avoid repetition. The computer readable storage medium includes a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0124] The embodiment of the present application provides a computer program product, the program product is stored in a storage medium, the program product is executed by at least one processor to realize the processes of the above-mentioned resource file cleaning method embodiments and achieve the same technical effects, and details are not repeated here to avoid repetition.

[0125] It should be noted that in this paper, the term "including", "containing" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or device including the element.

[0126] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-mentioned embodiment method can be realized by software and necessary general hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application or the part that contributes to the prior art can be embodied in the form of software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes a plurality of instructions to make a terminal (which can be a mobile phone, computer, server, air conditioner or network device) execute the method described in each embodiment of the present application.

[0127] The embodiments of the present application are described above with reference to the accompanying drawings, but the present application is not limited to the specific embodiments described above, and the specific embodiments described above are merely illustrative, but not restrictive, and those skilled in the art can make many forms under the inspiration of the present application without departing from the purpose of the present application and the scope protected by the claims, which all belong to the protection of the present application.

[0128] Those skilled in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in the embodiments of the present application can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software mode depends on the specific application and design constraints of the technical solution. The skilled person can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0129] Those skilled in the art can clearly understand that, for the convenience and brevity of the description, the specific working processes of the above-described system, device and unit can refer to the corresponding processes in the foregoing method embodiments, which will not be repeated here.

[0130] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed units can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0131] The units described as separate components can or can not be physically separated, and the components displayed as units can or can not be physical units, that is, they can be located in one place, or can be distributed on a plurality of network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0132] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit.

[0133] If the functions are realized in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application or the parts of the present application that essentially contribute to the prior art or the parts of the technical solutions can be embodied in the form of software products. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in the various embodiments of the present application. The aforementioned storage medium includes various storage media that can store program codes, such as a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk.

[0134] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A resource file cleaning method, characterized by, The method comprises: obtaining project code and a project resource package of an application; a code file in the project code file has a corresponding code identifier, and a resource file in the project resource package has a corresponding resource identifier; searching in the project code by using the resource identifier to obtain a first search result; if the first search result is that a target code file where the resource identifier is located is not a specified code file, searching in the project code by using a code identifier of the target code file to obtain a second search result; if the second search result is empty or the code identifier of the target code file is in the specified code file, ending the search of the resource identifier, and determining the resource identifier corresponding to the second search result being empty as a useless resource identifier, and determining the resource identifier corresponding to the code identifier of the target code file being in the specified code file as a useful resource identifier; cleaning up a resource file corresponding to the useless resource identifier in the project resource package.

2. The method of claim 1, wherein, The resource identifier is obtained by the following method: scanning a project directory of the project resource package to obtain a resource file path of a resource file; extracting a resource identifier of the resource file from the resource file path.

3. The method of claim 2, wherein, The resource file path comprises a submission time when the application is submitted to a system platform for managing the application, and the searching in the project code by using the resource identifier to obtain the first search result comprises: sequentially searching in the project code by using the resource identifier according to a time sequence of the submission time of the resource file to obtain the first search result.

4. The method of claim 1, wherein, After the searching in the project code by using the resource identifier to obtain the first search result, the method further comprises: if the first search result is empty, determining the corresponding resource identifier as a useless resource identifier.

5. The method of claim 1, wherein, After the searching in the project code by using the resource identifier to obtain the first search result, the method further comprises: if the first search result is that the target code file where the resource identifier is located is a specified code file, determining the corresponding resource identifier as a useful resource identifier.

6. The method of claim 1, wherein, After the searching in the project code by using the code identifier of the target code to obtain the second search result, the method further comprises: if the second search result is that the code identifier of the target code file is not in the specified code file, taking a code file where the code identifier of the target code file is located as a target code file, and returning to execute the step of searching in the project code by using the code identifier of the target code file to obtain the second search result.

7. The method according to any one of claims 1 to 6, characterized in that, The specified code file is a non-interface design file, and the specified code file is a Java file or a Kotlin file.

8. A resource file cleaning apparatus characterized by comprising: The device comprises: an obtaining module configured to obtain project code and a project resource package of an application; a code file in the project code file has a corresponding code identifier, and a resource file in the project resource package has a corresponding resource identifier; a first search module configured to search in the project code by using the resource identifier to obtain a first search result; The second search module is configured to search the project code by using the code identifier of the target code file to obtain a second search result if the first search result indicates that the target code file in which the resource identifier is located is not the specified code file. The determination module is configured to end the search of the resource identifier if the second search result is empty or the code identifier of the target code file is in the specified code file, and determine the resource identifier corresponding to the second search result being empty as a useless resource identifier, and determine the resource identifier corresponding to the code identifier of the target code file being in the specified code file as a useful resource identifier. The cleaning module is configured to clean a resource file corresponding to the useless resource identifier in the project resource package.

9. An electronic device, comprising: The apparatus includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory perform communication with each other through the communication bus. The memory is configured to store a computer program. The processor is configured to execute the program stored on the memory to implement the method in any one of claims 1 to 7.

10. One or more computer-readable media having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method of any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method and system for parallel cleaning of Android engineering useless resources

    CN106599151A

  • File cleaning method and device, processor and electronic device

    CN113448928A