Method and apparatus for processing application resource, electronic device, and storage medium
By obtaining the target resource subclass of the application, extracting valid resources, and comparing and deleting invalid resources, the problem of large size and high resource consumption caused by invalid resources in the application installation package is solved, thereby improving user experience and resource utilization efficiency.
Patent Information
- Application Number
- CN202210498986.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-09
- Publication Date
- 2026-01-27
- Estimated Expiration
- 2042-05-09
Smart Images

Figure CN114995839B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of application data processing technology, and in particular to an application resource processing method, an application resource processing apparatus, an electronic device, and a computer-readable storage medium. Background Technology
[0002] With the rapid development of the mobile internet, smart terminals have increasingly become the main platform for human-computer interaction. In real life, smart terminals have become essential for everyone, serving as a window for daily interaction with the world and playing a vital role for each individual. Application installation packages typically include many built-in application resources, such as images, audio, and text, to ensure a good user experience even without internet access. However, as application versions iterate, some application functions may be removed, but the corresponding application resources are still packaged into the application installation package. This results in invalid application resources in the installation package, increasing its size and leading to greater data consumption during downloads or updates. Furthermore, it can easily occupy the device's storage memory, significantly reducing the user experience. Summary of the Invention
[0003] The present invention provides a method, apparatus, electronic device, and computer-readable storage medium for processing application resources, in order to solve or partially solve the problem that invalid resources in the application installation package lead to a large installation package size.
[0004] This invention discloses a method for processing application resources, the method comprising:
[0005] Retrieve the target resource subclass of the target resource in the application;
[0006] Based on the target resource subclass, extract the valid application resources of the application from the preset installation package corresponding to the application;
[0007] The valid application resources are compared with the preset resource set corresponding to the application to obtain the invalid application resources in the application.
[0008] In response to the packaging instruction for the installation package, the invalid application resources are deleted from the preset resource set, and a target installation package corresponding to the application is generated.
[0009] Optionally, the target resource subclass is generated in the following manner:
[0010] Obtain the resource parent class of the application, the resource parent class includes an initial resource subclass, and the initial resource subclass includes an initial resource acquisition function;
[0011] Obtain resource information and collection framework class of the application resources currently used in the application;
[0012] The resource information and the collection framework class are written into the initial resource subclass to generate the target resource subclass.
[0013] Optionally, the effective application resources include the resources used by the application during its operation, and the preset installation package includes several application components. The step of extracting the effective application resources of the application from the preset installation package corresponding to the application according to the target resource subclass includes:
[0014] The target resource subclass is used to extract the runtime resources of the application from each of the application components.
[0015] Optionally, the application corresponds to a layout file, and the method further includes:
[0016] Obtain the file parsing interface and the layout filling factory class corresponding to the file parsing interface;
[0017] The layout file is parsed to obtain its configuration data.
[0018] Optionally, the layout filling factory class includes an attribute retrieval function, and the step of extracting the valid application resources of the application from the preset installation package corresponding to the application based on the target resource subclass further includes:
[0019] Retrieve the resource category corresponding to the attribute retrieval function;
[0020] The attribute retrieval function is used to obtain the resource attributes corresponding to the resource category from the configuration data of the layout file;
[0021] The preloaded resources of the application are extracted from each of the application components using the target resource subclass and the resource attributes.
[0022] Optionally, the resource attributes include at least the resource path and control information, and the step of extracting the preloaded resources of the application from each of the application components using the target resource subclass and the resource attributes includes:
[0023] The preloaded resources of the application are extracted from each of the application components using the target resource subclass, the resource path, and the control information.
[0024] Optionally, comparing the valid application resources with a preset resource set corresponding to the application to obtain invalid application resources in the application includes:
[0025] The runtime resources and the preloaded resources are compared with the preset resource set corresponding to the application to obtain invalid application resources in the application.
[0026] This invention discloses an application resource processing apparatus, the apparatus comprising:
[0027] The target resource subclass acquisition module is used to obtain the target resource subclass of the target resource in the application.
[0028] The effective application resource extraction module is used to extract the effective application resources of the application from the preset installation package corresponding to the application according to the target resource subclass;
[0029] The invalid application resource acquisition module is used to compare the valid application resources with a preset resource set corresponding to the application to obtain invalid application resources in the application.
[0030] The target installation package generation module is used to, in response to the packaging instruction for the installation package, delete the invalid application resources from the preset resource set and generate a target installation package corresponding to the application.
[0031] Optionally, the target resource subclass is generated through the following module:
[0032] A resource parent class acquisition module is used to acquire the resource parent class of the application, wherein the resource parent class includes an initial resource subclass, and the initial resource subclass includes an initial resource acquisition function;
[0033] The resource information acquisition module is used to acquire resource information of application resources currently used in the application and collection framework classes;
[0034] The target resource subclass generation module is used to write the resource information and the collection framework class into the initial resource subclass to generate the target resource subclass.
[0035] Optionally, the effective application resources include the resources used by the application during its operation, the preset installation package includes several application components, and the effective application resource extraction module includes:
[0036] The runtime resource extraction submodule is used to extract the runtime resources of the application from each of the application components using the target resource subclass.
[0037] Optionally, the application corresponds to a layout file, and the device further includes:
[0038] The layout fill factory class acquisition module is used to acquire the file parsing interface and the layout fill factory class corresponding to the file parsing interface;
[0039] The configuration data acquisition module is used to parse the layout file and obtain the configuration data of the layout file.
[0040] Optionally, the layout filling factory class includes attribute retrieval functions, and the effective application resource extraction module further includes:
[0041] The resource category acquisition submodule is used to acquire the resource category corresponding to the attribute acquisition function.
[0042] The resource attribute acquisition submodule is used to obtain the resource attribute corresponding to the resource category from the configuration data of the layout file using the attribute acquisition function;
[0043] The preloaded resource extraction submodule is used to extract the preloaded resources of the application from each of the application components using the target resource subclass and the resource attributes.
[0044] Optionally, the resource attributes include at least the resource path and control information, and the preloaded resource extraction submodule is specifically used for:
[0045] The preloaded resources of the application are extracted from each of the application components using the target resource subclass, the resource path, and the control information.
[0046] Optionally, the invalid application resource acquisition module is specifically used for:
[0047] The runtime resources and the preloaded resources are compared with the preset resource set corresponding to the application to obtain invalid application resources in the application.
[0048] This invention also discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0049] The memory is used to store computer programs;
[0050] When the processor executes a program stored in the memory, it implements the method described in the embodiments of the present invention.
[0051] This invention also discloses a computer-readable storage medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described in this invention.
[0052] The embodiments of the present invention have the following advantages:
[0053] In this embodiment of the invention, the target resource subclass of the application can be obtained first. Then, the valid application resources of the application can be extracted from the preset installation package corresponding to the application through the target resource subclass. The valid application resources are then compared with the preset resource set corresponding to the application to obtain invalid application resources in the application. In response to the packaging instruction for the installation package, the invalid application resources are deleted from the preset resource set, and the target installation package corresponding to the application is generated. Thus, the target resource subclass is used to quickly obtain valid application resources from all application resources in the application. By comparing the obtained valid application resources, the invalid application resources of the application can be found from the preset resource set. This effectively and quickly locates the invalid application resources of the application, improves the efficiency of application resource search, and allows invalid application resources to be deleted when the installation package is packaged, greatly reducing the resource burden and size of the target installation package. Attached Figure Description
[0054] Figure 1 This is a flowchart of the steps of an application resource processing method provided in an embodiment of the present invention;
[0055] Figure 2 This is a flowchart of the steps of an application resource processing method provided in an embodiment of the present invention;
[0056] Figure 3 This is a structural block diagram of an application resource processing device provided in an embodiment of the present invention;
[0057] Figure 4 This is a block diagram of an electronic device provided in an embodiment of the present invention;
[0058] Figure 5 This is a schematic diagram of a computer-readable medium provided in an embodiment of the present invention. Detailed Implementation
[0059] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0060] With the rapid development of the mobile internet, smart terminals have increasingly become the main platform for human-computer interaction. Especially in daily life, people can use various functions within applications through smart terminals. Each application's installation package typically includes many built-in application resources, such as image resources, audio resources, and text resources, to ensure a good user experience even without internet access. In practice, to meet user needs or optimize application functions, technical personnel need to update and iterate the application periodically. For different update or optimization requirements, technical personnel can deprecate certain methods to remove some application functions from the old version, then generate a new version's installation package and release it. However, the new version's installation package may still contain application resources corresponding to the removed functions.
[0061] As an example, a social application ① exists in a smart terminal. The version number of the social application ① currently optimized by the relevant technicians is v5.1. However, the application installation package corresponding to this social application ① includes the application resource data corresponding to the old version v4.1 and some deprecated application functions of the old version v4.2. Therefore, if the relevant technicians directly release the application installation package with the version number v5.1 to the download platform for users to download, there will be problems such as the application installation package of social application ① being too large and having a large amount of invalid application resource data. This will result in the new version of the application installation package containing invalid application resources, causing problems such as resource burden, low user conversion rate, and poor user experience.
[0062] One of the core inventive points of this invention is that it can first obtain the target resource subclass of the application, then extract the valid application resources of the application from the preset installation package corresponding to the application through the target resource subclass, and then compare the valid application resources with the preset resource set corresponding to the application to obtain invalid application resources in the application. In response to the packaging instruction for the installation package, the invalid application resources are deleted from the preset resource set, and the target installation package corresponding to the application is generated. Thus, by using the target resource subclass to quickly obtain valid application resources from all application resources in the application, and by comparing resources, invalid application resources of the application are found from the preset resource set based on the obtained valid application resources, effectively and quickly locating invalid application resources of the application, improving the efficiency of application resource search, and the invalid application resources can be deleted when the installation package is packaged, which greatly reduces the resource burden and size of the target installation package.
[0063] Reference Figure 1 The diagram illustrates a flowchart of a method for processing application resources according to an embodiment of the present invention, which may specifically include the following steps:
[0064] Step 101: Obtain the target resource subclass of the target resource in the application;
[0065] In this embodiment of the invention, those skilled in the art can use an object-oriented programming language to write applications. For example, Java can be used to implement various application functions. Java is an object-oriented programming language that not only possesses the advantages of C / C++, but also eliminates difficult-to-understand concepts such as multiple inheritance and pointers in C / C++. Therefore, Java has the characteristics of being powerful and easy to use. As a representative of static object-oriented programming languages, it implements object-oriented theory. In Java, the significance of a parent class lies in its ability to extract the commonalities of multiple types of things. In classes with inheritance relationships, the class before the keyword "extends" is the subclass. Since the subclass has methods with the same name, return type, and parameter list that are accessible (inheritable from the parent class), the subclass can inherit the characteristics and behavior of the parent class, so that the subclass object (instance) has the instance fields and methods of the parent class, or the subclass inherits methods from the parent class, so that the subclass has the same behavior as the parent class.
[0066] Optionally, the application can be a lifestyle application, an audio application, or a game application, etc. Lifestyle applications can be further subdivided according to different types, such as social applications, leisure and entertainment applications, and housekeeping service applications. This application embodiment uses a social application running on a smart terminal, such as a smartphone, as an example for illustrative purposes; it is understood that the present invention is not limited thereto.
[0067] Specifically, if the target resources are image resources, video resources, audio resources, and text resources in the preset installation package, then the target resource subclass of the target resource in the application can be a class that has all the attributes and operations of the parent class of different application resources, and at the same time has specific attributes or operations. It includes various methods such as searching for and retrieving image resources, video resources, audio resources, and text resources. For example, for image resources in a social application, the target resource subclass can be a custom "ResourceProxy class" corresponding to the image resources.
[0068] In the specific implementation, the target resource subclass can be generated through the following sub-steps:
[0069] Step S11: Obtain the resource parent class of the application, the resource parent class includes an initial resource subclass, and the initial resource subclass includes an initial resource acquisition function;
[0070] Specifically, the parent class of a resource can be a class inherited by the target resource subclass, also known as a superclass. Therefore, before generating the target resource subclass, it is necessary to first obtain the parent class of the resource corresponding to different application resources in the application, such as the "Resource class" corresponding to image resources. Then, a custom initial resource subclass "ResourceProxy class" is defined in the inheritance system "Resource class". Different initial resource acquisition functions can be overridden in the initial resource subclass for different application resources. For example, for image resources in the application, the "getDrawable method" can be overridden in the initial resource subclass. Correspondingly, for application resources such as text resources and audio resources, an initial resource acquisition function corresponding to the type of application resource can be used. This invention does not limit this. Thus, by customizing the relevant information of the required application resources in the initial resource acquisition function, the application resources corresponding to the custom relevant information can be obtained. For example, the custom relevant information can be: obtain the image resources currently used in the application, or obtain the text resources currently used in the application, etc.
[0071] Step S12: Obtain the resource information and collection framework class of the application resources currently used in the application;
[0072] Specifically, the application resources currently used in the application can be obtained by first overriding the `getDrawable` method in the initial resource subclass. Then, the resource information corresponding to the currently used application resource and the collection framework class can be obtained. For example, the application resource can be an image resource, and the resource information of the image resource can be the image name, the image resource path, etc. Then, a collection object for storing application resources can be generated based on the collection framework class. For example, an in-memory collection for storing image names can be generated using the collection framework class. Thus, the resource information corresponding to the currently used application resource can be stored in the collection object using the collection framework class, so that relevant technical personnel can quickly extract the required application resources from the application, improving the efficiency of application resource lookup.
[0073] The collection framework class is provided by Java and can be used to store multiple elements. The collection framework class includes various collection objects. For example, ArrayList can be used to implement functions such as adding, deleting, modifying, and traversing, while HashSet can be used to store non-duplicate objects. In this way, collection objects such as ArrayList or HashSet can be used to store resource information corresponding to application resources, making it convenient to upload the currently used resource information to the server later using collection objects.
[0074] Step S13: Write the resource information and the collection framework class into the initial resource subclass to generate the target resource subclass.
[0075] Specifically, the resource information corresponding to the application resources and the collection framework class can be written into the initial resource subclass, which includes the initial resource acquisition function, to generate a target resource subclass that has functions such as searching for application resources, acquiring application resource information, and recording resource information.
[0076] Step 102: Based on the target resource subclass, extract the valid application resources of the application from the preset installation package corresponding to the application.
[0077] In this embodiment of the invention, the application resources currently in use are obtained by overriding the initial resource acquisition function in the target resource subclass. At the same time, a corresponding collection framework class is configured for the application resources in the target resource subclass. The resource information of the application resources is stored using the collection object generated by the collection framework class. Then, the valid application resources of the application are extracted from the application's preset installation package.
[0078] Optionally, Android applications can be written in the high-level programming language "Java". It utilizes the Android SDK to compile code and packages all resource files and data into an APK (Application Package) file. The default installation package can be an unreleased application installation package APK (Android Package, or APK for short), which contains the application's resource configuration files, binary files, resource index tables, resource files, certificate signing files, layout files, etc. Resource files can be stored in the Res (Resource) directory. Each file in the resource directory can be mapped to a .R file in the Android project, generating a corresponding resource ID. Access can be performed directly using the resource ID to perform indexing operations. Furthermore, the Res directory can contain various folders, such as the drawable directory for storing graphic resources, the layout directory for storing layout files, the values directory for storing feature values, and colors.xml for storing color values, etc. The resource configuration file contains the application's name, version number, user permissions, registered services, linked other applications, declaration of the four major components, and calling information, etc. It can be used to record the mapping relationship between resource files and resource IDs. Thus, when a user uses a custom target resource subclass to extract valid application resources from an APK, the corresponding resource path can be found based on the application resource's resource ID to determine the valid application resource being searched.
[0079] Specifically, valid application resources can be resource data called by the latest version of the application, such as image resource data currently being displayed in the application and image resource data that is not currently displayed but is specified for reference. In the process of extracting the currently used valid application resources, the valid application resources can be divided into runtime resources called by code and preloaded resources specified for reference by layout files according to the way the application resources are called. Different methods are used to locate or extract different valid application resources to ensure the completeness and accuracy of the extracted application resources.
[0080] In one embodiment of the present invention, the preset installation package includes several application components. If the valid application resources are the runtime resources currently used in the application, the runtime resources of the application can be directly extracted from each application component using the target resource subclass.
[0081] Optionally, the runtime resources can be application resources controlled by calling methods in Java program code. The application components in the default installation package can be several Activity components, which are the visual interfaces for users to interact with the application. They can include buttons, images, TextViews, or other visual components. The view component objects can be obtained from each Activity component through the target resource subclass, and then a view object is returned with the resource ID of the component as a parameter, thus obtaining the runtime resources corresponding to the view object.
[0082] In one example, assuming the application is a social application and the resources it uses are the image resources currently being used by the social application, a custom ResourceProxy class (target resource subclass) can be defined by inheriting the Resource class (resource parent class) from the image resource system. The getDrawable method (initial resource acquisition function) can be overridden, and the overridden getDrawable method can be used to obtain the name of the currently used image resource. The name of the currently used image resource (resource information) is then saved to an in-memory collection (collection framework class). When the social application goes into the background, it can report the in-memory collection containing the name of the currently used image resource to the server. Thus, by overriding the getDrawable method, the currently used image resource can be quickly obtained from various Activity components.
[0083] In another embodiment of the present invention, the application corresponds to a layout file. If the valid application resource is a preloaded resource that is specified to be referenced in the application, the file parsing interface and the layout filling factory class corresponding to the file parsing interface can be obtained first, and then the layout file can be parsed to obtain the configuration data of the layout file.
[0084] Optionally, the preloaded resources can be application resources referenced via XML attributes in the layout file. The layout file is used to define the user interface in the res / layout directory of the Android application. The file parsing interface can be the LayoutInflater.Factory2 interface, which is used to obtain attributes and rebuild the View. The layout inflater factory class can be a class corresponding to the LayoutInflater.Factory2 interface, which at least includes attribute retrieval functions for attribute parsing. In the Android system, after parsing the XML layout file using parsers such as XmlpullParser, it is necessary to first determine whether a class with the specified LayoutInflater.Factory2 interface exists. If a class with the specified interface exists, the methods in the specified class can be called to perform attribute parsing and obtain the configuration data of the layout file.
[0085] In practical implementation, attribute retrieval functions can be pre-written in the layout fill factory class. For example, for image resources in social applications, the attribute retrieval functions can be the onCreateView method and the onCreate method. The onCreate method is called when the Activity is initialized. When a subclass overrides the onCreate method, it must call the parent class's onCreate method to avoid throwing exceptions. Then, the View is created through the onCreateView in the Activity component, thereby obtaining the attributes of the application resources. Then, the resource category of the required application resources is determined according to the type of the attribute retrieval function, such as image resources, text resources, audio resources, etc. Then, the attribute retrieval function is used to obtain at least one resource attribute corresponding to the resource category from the configuration data of the layout file. Finally, the preloaded resources of the application are extracted from each application component using the target resource subclass and the resource attribute.
[0086] Specifically, the configuration data can include the width, height, orientation, spacing, and position of controls in the layout file, the font of the text in the TextView, the visibility of controls, the background image, the relative position in the parent layout, and the relative position of a control, etc. The resource attributes obtained using the attribute retrieval function include at least the resource path and control information. The control information can be the defined background image "background". Therefore, the preloaded resources of the application can be extracted from various application components through the target resource subclass, resource path, and control information.
[0087] In one example, assuming the application is a social application and the preloaded resources are image resources specifically referenced in the application, a custom layout inflater factory class implementing the LayoutInflater.Factory2 interface can be used. Then, using bytecode instrumentation, the onCreateView method is implemented through the layout inflater factory class before calling super in the onCreate method of all Activity components. The onCreateView method and the onCreate method are then used to obtain the src (resource path) of the layout file and the image resource ID specified by the background attribute in all Activity components. The getDrawable method of the Resource class is then called to obtain the name of the currently used image resource and saved to a memory collection. When the social application enters the background, the memory collection including the name of the specified referenced image resource can be reported to the server. Thus, through the target resource subclass, the LayoutInflater.Factory2 interface, the layout inflater factory class, and the getDrawable method, the specified referenced image resource can be quickly obtained from each Activity component. Furthermore, bytecode instrumentation is used to monitor the specified referenced image resource and count the resource names of the obtained specified referenced image resources.
[0088] Step 103: Compare the valid application resources with the preset resource set corresponding to the application to obtain the invalid application resources in the application;
[0089] In this embodiment of the invention, the preset resource set can be all application resources of the application, which may include currently used runtime resources, preloaded resources with specified references, and invalid application resources corresponding to application functions that have been deprecated during application updates. Invalid application resources are resources that are not associated with any application function in the latest version of the application. For example, if the control used for finding data has been removed in the latest version of the application, then the image resource data corresponding to the control is an invalid application resource.
[0090] In practice, the runtime resources and preloaded resources can be compared with the application's corresponding preset resource set to obtain invalid application resources in the application. In this way, invalid application resources can be found by comparing the currently used runtime resources and the specified referenced preloaded resources in the application with all application resources in the APK.
[0091] In one example, assuming the application is a social application, the currently used image resource A can be obtained by calling the getDrawable method of the Resource object. Then, the image resource B corresponding to the specified reference in the layout file XML with the src or background attribute can be obtained. When the application enters the background, the resource information corresponding to image resource A and image resource B is recorded in a collection object and uploaded to the server. The server can compare the image resource A and image resource B with the image names of all application resources in the APK. If the image names match, they are valid application resources; if the image names do not match, they are invalid application resources.
[0092] Step 104: In response to the packaging instruction for the installation package, delete the invalid application resources from the preset resource set and generate a target installation package corresponding to the application.
[0093] In this embodiment of the invention, the server compares the running resources, preloaded resources, and all application resources in the preset resource set to obtain invalid applications for the current version of the application. Then, in response to the packaging instruction for the application's installation package, relevant technical personnel can delete invalid application resources from the preset resource set according to actual needs and generate a target installation package corresponding to the current version of the application to reduce the size of the installation package and thus improve the user conversion rate.
[0094] Optionally, the target installation package corresponding to the application includes currently used runtime resources and preloaded resources that are specified for reference. Relevant technical personnel can release the target installation package, which has removed some or all invalid application resources, for users to download and update, thereby reducing resource burden, improving user conversion rate, and enhancing user experience.
[0095] In this embodiment of the invention, the target resource subclass of the application can be obtained first. Then, the valid application resources of the application can be extracted from the preset installation package corresponding to the application through the target resource subclass. The valid application resources are then compared with the preset resource set corresponding to the application to obtain invalid application resources in the application. In response to the packaging instruction for the installation package, the invalid application resources are deleted from the preset resource set, and the target installation package corresponding to the application is generated. Thus, the target resource subclass is used to quickly obtain valid application resources from all application resources in the application. By comparing the obtained valid application resources, the invalid application resources of the application can be found from the preset resource set. This effectively and quickly locates the invalid application resources of the application, improves the efficiency of application resource search, and allows invalid application resources to be deleted when the installation package is packaged, greatly reducing the resource burden and size of the target installation package.
[0096] To enable those skilled in the art to better understand the technical solutions of the embodiments of the present invention, an example is provided below, along with reference to... Figure 2 The flowchart shown illustrates an embodiment of the present invention.
[0097] Before processing application resources, the currently used valid application resources in the application are divided into runtime resources and preloaded resources according to different calling methods. Then, different extraction methods are used to obtain resource information, such as resource name, from the valid application resources.
[0098] S21. For the currently used runtime resources, if the runtime resources are image resources, first define a custom ResourceProxy class that inherits from the system Resource class, then override the getDrawable method to obtain the image resources, and save the image resource name to the image resource collection. When the application enters the background, the image resource collection will be reported to the server.
[0099] S22. For a preloaded resource with a specified reference, if the preloaded resource is an image resource, a custom layout fill factory class implements the LayoutInflater.Factory2 interface and implements the onCreateView method. In the onCreateView method, the src and background attribute values are obtained, thereby obtaining the image resource corresponding to the src and background attribute values. Then, the getDrawable method in the Resource class is called to trigger the reporting logic for the image resource name in S11.
[0100] S23. Write a Gradle plugin to implement bytecode instrumentation during the packaging process, override the getResources method of all Activity components to return a custom ResourceProxy class, and specify a custom layout fill factory class before calling super in the onCreate method.
[0101] S24. The server retrieves the set of image resources that are not used online, i.e., invalid application resources, based on the set of image resources built into the APK and the set of image resources that are in use.
[0102] S25. Relevant technical personnel shall delete invalid online application resources according to the actual situation in order to reduce the size of the application installation package.
[0103] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0104] Reference Figure 3 The diagram illustrates a structural block diagram of an application resource processing device provided in an embodiment of the present invention, which may specifically include the following modules:
[0105] The target resource subclass acquisition module 301 is used to acquire the target resource subclass of the target resource in the application.
[0106] The effective application resource extraction module 302 is used to extract the effective application resources of the application from the preset installation package corresponding to the application according to the target resource subclass;
[0107] The invalid application resource acquisition module 303 is used to compare the valid application resources with the preset resource set corresponding to the application to obtain the invalid application resources in the application.
[0108] The target installation package generation module 304 is used to delete the invalid application resources from the preset resource set and generate a target installation package corresponding to the application in response to the packaging instruction for the installation package.
[0109] In one alternative embodiment, the target resource subclass is generated through the following module:
[0110] A resource parent class acquisition module is used to acquire the resource parent class of the application, wherein the resource parent class includes an initial resource subclass, and the initial resource subclass includes an initial resource acquisition function;
[0111] The resource information acquisition module is used to acquire resource information of application resources currently used in the application and collection framework classes;
[0112] The target resource subclass generation module is used to write the resource information and the collection framework class into the initial resource subclass to generate the target resource subclass.
[0113] In one optional embodiment, the effective application resources include the resources used by the application during operation, the preset installation package includes several application components, and the effective application resource extraction module 302 includes:
[0114] The runtime resource extraction submodule is used to extract the runtime resources of the application from each of the application components using the target resource subclass.
[0115] In one alternative embodiment, the application corresponds to a layout file, and the apparatus further includes:
[0116] The layout fill factory class acquisition module is used to acquire the file parsing interface and the layout fill factory class corresponding to the file parsing interface;
[0117] The configuration data acquisition module is used to parse the layout file and obtain the configuration data of the layout file.
[0118] In one optional embodiment, the layout filling factory class includes an attribute acquisition function, and the effective application resource extraction module 302 further includes:
[0119] The resource category acquisition submodule is used to acquire the resource category corresponding to the attribute acquisition function.
[0120] The resource attribute acquisition submodule is used to obtain the resource attribute corresponding to the resource category from the configuration data of the layout file using the attribute acquisition function;
[0121] The preloaded resource extraction submodule is used to extract the preloaded resources of the application from each of the application components using the target resource subclass and the resource attributes.
[0122] In one optional embodiment, the resource attributes include at least the resource path and control information, and the preloaded resource extraction submodule is specifically used for:
[0123] The preloaded resources of the application are extracted from each of the application components using the target resource subclass, the resource path, and the control information.
[0124] In one optional embodiment, the invalid application resource acquisition module 303 is specifically used for:
[0125] The runtime resources and the preloaded resources are compared with the preset resource set corresponding to the application to obtain invalid application resources in the application.
[0126] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0127] In addition, embodiments of the present invention also provide an electronic device, such as... Figure 4As shown, it includes a processor 401, a communication interface 402, a memory 403, and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404.
[0128] Memory 403 is used to store computer programs;
[0129] When processor 401 executes the program stored in memory 403, it performs the following steps:
[0130] Retrieve the target resource subclass of the target resource in the application;
[0131] Based on the target resource subclass, extract the valid application resources of the application from the preset installation package corresponding to the application;
[0132] The valid application resources are compared with the preset resource set corresponding to the application to obtain the invalid application resources in the application.
[0133] In response to the packaging instruction for the installation package, the invalid application resources are deleted from the preset resource set, and a target installation package corresponding to the application is generated.
[0134] In one alternative embodiment, the target resource subclass is generated in the following manner:
[0135] Obtain the resource parent class of the application, the resource parent class includes an initial resource subclass, and the initial resource subclass includes an initial resource acquisition function;
[0136] Obtain resource information and collection framework class of the application resources currently used in the application;
[0137] The resource information and the collection framework class are written into the initial resource subclass to generate the target resource subclass.
[0138] In one optional embodiment, the effective application resources include the resources used by the application during its operation, the preset installation package includes several application components, and the step of extracting the effective application resources of the application from the preset installation package corresponding to the application according to the target resource subclass includes:
[0139] The target resource subclass is used to extract the runtime resources of the application from each of the application components.
[0140] In one alternative embodiment, the application corresponds to a layout file, and the method further includes:
[0141] Obtain the file parsing interface and the layout filling factory class corresponding to the file parsing interface;
[0142] The layout file is parsed to obtain its configuration data.
[0143] In one optional embodiment, the layout filling factory class includes an attribute retrieval function, and the step of extracting the valid application resources of the application from the preset installation package corresponding to the application based on the target resource subclass further includes:
[0144] Retrieve the resource category corresponding to the attribute retrieval function;
[0145] The attribute retrieval function is used to obtain the resource attributes corresponding to the resource category from the configuration data of the layout file;
[0146] The preloaded resources of the application are extracted from each of the application components using the target resource subclass and the resource attributes.
[0147] In one optional embodiment, the resource attributes include at least resource paths and control information, and the step of extracting preloaded resources of the application from each of the application components using the target resource subclass and the resource attributes includes:
[0148] The preloaded resources of the application are extracted from each of the application components using the target resource subclass, the resource path, and the control information.
[0149] In one optional embodiment, comparing the valid application resources with a preset resource set corresponding to the application to obtain invalid application resources in the application includes:
[0150] The runtime resources and the preloaded resources are compared with the preset resource set corresponding to the application to obtain invalid application resources in the application.
[0151] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0152] The communication interface is used for communication between the aforementioned terminal and other devices.
[0153] The memory may include random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0154] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0155] like Figure 5 As shown, in another embodiment of the present invention, a computer-readable storage medium 501 is also provided, which stores instructions that, when executed on a computer, cause the computer to perform the application resource processing method described in the above embodiments.
[0156] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the application resource processing method described in the above embodiments.
[0157] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0158] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0159] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the system embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0160] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention are included within the scope of protection of the present invention.
Claims
1. A method for processing application resources, characterized in that, include: Obtain the application's resource parent class, which includes an initial resource subclass, and the initial resource subclass includes different initial resource acquisition functions rewritten for different application resources; The resource information and collection framework class of the application resources currently used in the application are obtained according to the initial resource acquisition function; Write the resource information and the collection framework class into the initial resource subclass to generate the target resource subclass; Based on the target resource subclass, extract the valid application resources of the application from the preset installation package corresponding to the application; The valid application resources are either the runtime resources currently used in the application or the preloaded resources of the specified application in the application. The valid application resources are compared with the preset resource set corresponding to the application to obtain the invalid application resources in the application. In response to the packaging instruction for the installation package, the invalid application resources are deleted from the preset resource set, and a target installation package corresponding to the application is generated.
2. The method according to claim 1, characterized in that, The preset installation package includes several application components. The step of extracting the valid application resources of the application from the preset installation package corresponding to the application, based on the target resource subclass, includes: The target resource subclass is used to extract the runtime resources of the application from each of the application components.
3. The method according to claim 2, characterized in that, The application corresponds to a layout file, and the method further includes: Obtain the file parsing interface and the layout filling factory class corresponding to the file parsing interface; The layout file is parsed to obtain its configuration data.
4. The method according to claim 3, characterized in that, The layout filling factory class includes attribute retrieval functions, and the step of extracting the valid application resources of the application from the preset installation package corresponding to the application based on the target resource subclass further includes: Retrieve the resource category corresponding to the attribute retrieval function; The attribute retrieval function is used to obtain the resource attributes corresponding to the resource category from the configuration data of the layout file; The preloaded resources of the application are extracted from each of the application components using the target resource subclass and the resource attributes.
5. The method according to claim 4, characterized in that, The resource attributes include at least the resource path and control information. The step of extracting the preloaded resources of the application from each of the application components using the target resource subclass and the resource attributes includes: The preloaded resources of the application are extracted from each of the application components using the target resource subclass, the resource path, and the control information.
6. The method according to claim 5, characterized in that, The step of comparing the valid application resources with a preset resource set corresponding to the application to obtain invalid application resources in the application includes: The runtime resources and the preloaded resources are compared with the preset resource set corresponding to the application to obtain invalid application resources in the application.
7. An application resource processing device, characterized in that, include: The resource parent class acquisition module is used to acquire the application's resource parent class, which includes an initial resource subclass. The initial resource subclass includes different initial resource acquisition functions rewritten for different application resources. The resource information acquisition module is used to acquire the resource information of the application resources currently used in the application and the collection framework class according to the initial resource acquisition function; The target resource subclass generation module is used to write the resource information and the collection framework class into the initial resource subclass to generate the target resource subclass; The effective application resource extraction module is used to extract the effective application resources of the application from the preset installation package corresponding to the application according to the target resource subclass; the effective application resources are the currently used runtime resources of the application or the preloaded resources of the specified application in the application. The invalid application resource acquisition module is used to compare the valid application resources with a preset resource set corresponding to the application to obtain invalid application resources in the application. The target installation package generation module is used to, in response to the packaging instruction for the installation package, delete the invalid application resources from the preset resource set and generate a target installation package corresponding to the application.
8. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes a program stored in the memory, it implements the method as described in any one of claims 1-6.
9. A computer-readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1-6.
Citation Information
Patent Citations
An application program optimization method and device
CN113448932A