Resource Update Method, Device, Equipment and Readable Storage Medium for Application Program

By replacing the parent class loader in the class loader chain during application operation and using the plug-in class loader to load update resources, the problem of complex and inefficient application update process is solved, and no restart is achieved, improving user experience and efficiency.

CN115129348BActive Publication Date: 2025-07-29TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210788001.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-04
Publication Date
2025-07-29
Estimated Expiration
2042-07-04

AI Technical Summary

Technical Problem

The update process of existing applications is complicated and requires repackaging, testing and restarting, resulting in poor human-computer interaction experience and low update efficiency, especially in scenarios such as live broadcast and payment, business processes are forced to be interrupted.

Method used

During the application running process, obtain the update resource package, create the plug-in class loader, and replace the parent class loader of the host class loader, generate the target class loader chain, and load the update resource through the target class loader to achieve functional operation.

Benefits of technology

Improves the efficiency of application updates, avoids the restart process, ensures the continuity of business processes, and improves user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115129348B_ABST
    Figure CN115129348B_ABST
Patent Text Reader

Abstract

The present application provides a method and a device for updating resources of an application. The method includes: during the running of the application, obtaining an update resource package of the application, where the update resource package includes update resources and an executable file; based on the executable file, creating a plugin class loader corresponding to the update resource package, and generating a class loader set including at least one non-plugin class loader; in the class loader chain corresponding to the application, obtaining a host class loader, and replacing the parent class loader of the host class loader with the plugin class loader to obtain a target class loader chain; determining a target class loader for loading a target class to which the update resource belongs based on at least one of the class loader set and the target class loader chain; loading the target class through the target class loader, and running the function corresponding to the target class based on the update resources. Through the present application, it is possible to implement the update of the application during the running of the program and improve the update efficiency of the application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a method, apparatus, device, computer-readable storage medium, and computer program product for updating resources of an application program. Background Art

[0002] With the popularization of computer technology, there are more and more application programs in computers. In the actual use process, various functions of the application program can be continuously improved through updates.

[0003] However, in the related art, no matter how much content the application program is updated, steps such as repackaging, testing, replacing the installation package in the corresponding channel, prompting the user to upgrade, and performing an overwrite installation after the user upgrades are required. The update process of the application program is relatively complex, which requires excessive manpower and costs. At the same time, when updating the application program, the application program needs to be restarted. In application scenarios such as live broadcast and payment, the ongoing business process is forced to be interrupted, resulting in a poor human-computer interaction experience and low application program update efficiency. Summary of the Invention

[0004] Embodiments of this application provide a method, apparatus, device, computer-readable storage medium, and computer program product for updating resources of an application program, which can update the application program during the operation of the application program and improve the update efficiency of the application program.

[0005] The technical solution of the embodiments of this application is implemented as follows:

[0006] Embodiments of this application provide a method for updating resources of an application program, including:

[0007] During the running process of the application program, obtain an update resource package of the application program, where the update resource package includes update resources and an executable file;

[0008] Based on the executable file, create a plug-in class loader corresponding to the update resource package, and generate a class loader set including at least one non-plug-in class loader;

[0009] In the class loader chain corresponding to the application program, obtain a host class loader, and replace the parent class loader of the host class loader with the plug-in class loader to obtain a target class loader chain;

[0010] Based on at least one of the class loader set and the target class loader chain, determine a target class loader for loading a target class to which the update resource belongs;

[0011] Load the target class through the target class loader, and run the function corresponding to the target class based on the update resource.

[0012] An embodiment of this application provides a resource update device for an application, including:

[0013] An acquisition module, configured to acquire an update resource package of the application during the running of the application, where the update resource package includes update resources and an executable file;

[0014] A generation module, configured to create a plugin class loader corresponding to the update resource package based on the executable file, and generate a class loader set including at least one non-plugin class loader;

[0015] A replacement module, configured to obtain a host class loader in a class loader chain corresponding to the application, and replace a parent class loader of the host class loader with the plugin class loader to obtain a target class loader chain;

[0016] A search module, configured to determine a target class loader for loading a target class to which the update resource belongs based on at least one of the class loader set and the target class loader chain;

[0017] An operation module, configured to load the target class through the target class loader, and run a function corresponding to the target class based on the update resource.

[0018] In the above solution, the search module is further configured to determine a target class loader for loading a target class to which the update resource belongs based on class loaders corresponding to each node in the target class loader chain;

[0019] When the target class loader cannot be determined based on the target class loader chain, determine the target class loader based on class loaders in the class loader set;

[0020] Wherein, class loaders in the target class loader chain have a hierarchical relationship, and class loaders in the class loader set do not have a hierarchical relationship.

[0021] In the above solution, the search module is further configured to determine a sub-hierarchical relationship with the plugin class loader as the lowest level based on the hierarchical relationship between class loaders in the target class loader chain;

[0022] Starting from the plugin class loader, obtain class loading paths of class loaders at each level in the sub-hierarchical relationship;

[0023] Obtain a target class loading path of the target class, and compare the target class loading path with each of the class loading paths to obtain a comparison result;

[0024] When the comparison result indicates that the target class loading path is different from any of the class loading paths, use the plug-in class loader as the target class loader for the target class.

[0025] In the above solution, the search module is further configured to obtain the class loading paths of various class loaders in the class loader set;

[0026] Obtain the target class loading path of the target class, and search for the target class loading path in the class loading paths of various class loaders to obtain a search result;

[0027] When the search result indicates that the target class loading path exists in the class loading paths of various class loaders, use the class loader to which the class loading path belongs as the target class loader.

[0028] In the above solution, the search module is further configured to identify the type of the target class to which the updated resource belongs, and the type includes a host class and a plug-in class;

[0029] Among them, the host class is a class loaded by the host class loader when installing the application, and the plug-in class is a class loaded by the plug-in class loader when running the application;

[0030] In the above solution, the search module is further configured to, when the type is a host class, determine a target class loader for loading the target class from at least one non-plug-in class loader in the class loader set;

[0031] When the type is a plug-in class, obtain a set of reference class identifiers corresponding to the plug-in class loader, and determine a target class loader for loading the target class based on one of the class loader set and the target class loader chain, and the set of reference class identifiers;

[0032] Among them, the reference class identifier is the class identifier of other classes referenced in the plug-in class loader.

[0033] In the above solution, the search module is further configured to match the class identifier of the target class with various class identifiers in the set of reference class identifiers to obtain a matching result;

[0034] When the matching result indicates that the class identifier of the target class belongs to the set of reference class identifiers, determine a target class loader for loading the target class based on the class loader set;

[0035] When the matching result indicates that the class identifier of the target class does not belong to the set of reference class identifiers, determine a target class loader for loading the target class based on the target class loader chain.

[0036] In the above solution, the running module is further configured to obtain the resource loading path of the update resource and the resource loader of the application program;

[0037] Before the original resource loading path of the application program in the resource loader, insert the resource loading path to obtain a target resource loading path;

[0038] According to the loading order indicated by the target resource loading path, load the update resource into the memory space of the application program.

[0039] In the above solution, the running module is further configured to, when the target class loader of the target class can be determined based on at least one of the class loader set and the target class loader chain, obtain the class loading path of the target class, and control the target class loader to perform a loading operation on the target class based on the class loading path;

[0040] During the execution of the loading operation, based on the resource identifier of the update resource, obtain the update resource from the memory space of the application program, and when the loading operation is completed, run the function corresponding to the target class after the resource is updated based on the update resource.

[0041] In the above solution, the running module is further configured to, when the target class loader of the target class cannot be determined based on at least one of the class loader set and the target class loader chain, control the plug-in class loader to capture exception information, and generate an error prompt message based on the exception information;

[0042] When running the function corresponding to the target class, display the error prompt message;

[0043] Wherein, the error prompt message is used to indicate that the update operation on the application program based on the update resource package fails.

[0044] In the above solution, the obtaining module is further configured to, during the running of the application program, receive an update notification sent by the server, where the update notification is used to indicate that there is an update resource package for the application program;

[0045] According to the update notification, download the update resource package to the local storage space, and notify the process of the application program, so that the process obtains the update resource package from the local storage space.

[0046] In the above solution, the generating module is further configured to parse the executable file to obtain at least one class to be loaded included in the update resource package;

[0047] Create a plug-in class loader for loading the at least one class to be loaded;

[0048] The generation of the class loader set including at least one non-plug-in class loader includes:

[0049] Obtain at least one non-plug-in class loader corresponding to the application, and generate a class loader set including at least one non-plug-in class loader and other plug-in class loaders except the plug-in class loader.

[0050] An embodiment of the present application provides an electronic device, including:

[0051] A memory for storing executable instructions;

[0052] A processor, when executing the executable instructions stored in the memory, implements the resource update method of the application provided by the embodiment of the present application.

[0053] An embodiment of the present application provides a computer-readable storage medium storing executable instructions for causing a processor to implement the resource update method of the application provided by the embodiment of the present application when executed.

[0054] An embodiment of the present application provides a computer program product including a computer program or instruction for causing a processor to implement the resource update method of the application provided by the embodiment of the present application when executed.

[0055] The embodiment of the present application has the following beneficial effects:

[0056] Applying the embodiment of the present application, during the running of the application, obtain the update resource package for the application, create a plug-in class loader corresponding to the update resource package, and then replace the parent class loader in the class loader chain of the application with the plug-in class loader to obtain the target class loader chain. In this way, it can be ensured that when performing resource update, the plug-in class loader is preferentially used to load the target class to which the update resource belongs; at the same time, combining the target class loader chain and the class loader set to determine the target class loader can ensure the accuracy of determining the target class loader and improve the search efficiency of the target class loader; using the target class loader to load the target class and run the function associated with the update resource can, in this way, realize the update of the application during the program running and improve the update efficiency of the application. Description of the Drawings

[0057] Figure 1 is a schematic diagram of the architecture of the resource update system of the application provided by the embodiment of the present application;

[0058] Figure 2 is a schematic diagram of the structure of the electronic device 500 for resource update of the application provided by the embodiment of the present application;

[0059] Figure 3 It is a schematic flowchart of a method for updating resources of an application provided by an embodiment of the present application;

[0060] Figure 4 It is a determination method of a target class loader provided by an embodiment of the present application;

[0061] Figure 5 It is a flowchart of a method for determining a target class loader based on a target class loader chain provided by an embodiment of the present application;

[0062] Figure 6 It is a flowchart of a method for determining a target class loader based on a class loader set provided by an embodiment of the present application;

[0063] Figure 7 It is a flowchart of a method for determining a target class loader based on the type of a target class provided by an embodiment of the present application;

[0064] Figure 8 It is a flowchart of a resource loading method for updating resources provided by an embodiment of the present application;

[0065] Figure 9 It is a flowchart of a loading method for a target class and updated resources provided by an embodiment of the present application;

[0066] Figure 10 It is a flowchart of a method for obtaining an update resource package of an application provided by an embodiment of the present application;

[0067] Figure 11 It is a flowchart of a method for obtaining an update resource package of an application provided by an embodiment of the present application;

[0068] Figure 12 It is a schematic flowchart of a process for loading updated resources provided in the related art;

[0069] Figure 13 It is a schematic flowchart of a process for loading updated resources provided by an embodiment of the present application;

[0070] Figure 14 It is a flowchart of a method for resource loading reference provided in the related art;

[0071] Figure 15 It is a flowchart of a method for resource loading reference provided by an embodiment of the present application;

[0072] Figure 16 It is a flowchart of a method for dynamically loading classes provided by an embodiment of the present application;

[0073] Figure 17 It is a flowchart of a class loading method provided in the related art;

[0074] Figure 18 It is a flowchart of the loading method of the class referenced by the updated resource package provided by the embodiments of the present application;

[0075] Figure 19 It is a schematic diagram of the method for dynamically loading classes based on multiple updated resource packages provided by the embodiments of the present application. Detailed implementation manners

[0076] In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be construed as limiting the present application. All other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the present application.

[0077] In the following description, reference is made to "some embodiments", which describe a subset of all possible embodiments. However, it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict.

[0078] If similar descriptions such as "first / second" appear in the application documents, the following description is added. In the following description, the terms "first\second\third" involved are only used to distinguish similar objects and do not represent a specific order for the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence when allowed, so that the embodiments of the present application described here can be implemented in an order other than that illustrated or described here.

[0079] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0080] Before further elaborating on the embodiments of the present application, the nouns and terms involved in the embodiments of the present application are described. The nouns and terms involved in the embodiments of the present application are subject to the following explanations.

[0081] 1) Patch package: A file used to repair vulnerabilities or errors in an application. Usually, the size of the patch package is much smaller than the size of the Android installation package (APK, Android Package) of the application. Existing patch package solutions are all based on function replacement or function hook (hook), and are usually used to make logical modifications to a small number of function methods in the application. When making modifications, it is not allowed to modify the function method name, the number and order of parameters.

[0082] 2) Dex (Dalvik Virtual Machine Execute) file: An executable file on the Android platform with the file extension.dex. Usually, an application APK contains a Dex file, which contains all the classes corresponding to the application. Each class contains its respective function methods to implement various functions of the application.

[0083] 3) Parent Delegation Mechanism: If a class loader receives a class loading request, it will not load it by itself first, but delegate this request to the class loader of its parent class for execution; if the parent class loader still has its own parent class loader, it will further delegate upward recursively, and the request will finally reach the top-level Bootstrap Class Loader; if the parent class loader can complete the class loading task, it will return successfully. If the parent class loader cannot complete the loading task, the child loader will try to load it by itself. This is the Parent Delegation Mechanism; the parent class loader distributes tasks layer by layer downward. If the child class loader can load a class, it will load this class. If the loading task cannot be completed even when distributed to the System Class Loader, an exception will be thrown.

[0084] 4) Plug-in: A type of app compressed package for Android terminals that can be installed without installation, usually in formats such as dex, apk, zip, etc.

[0085] 5) Hot Deployment: A new code modification feature can be dynamically loaded into the process memory and run normally without restarting the process, thereby replacing the original old code feature.

[0086] 6) Android Resources: An Android apk contains several parts, including the code dex, dynamic link library so, Android resources, and configuration files. Android resources include image resources, resource configuration files, etc.

[0087] Based on the above explanations of the nouns and terms involved in the embodiments of the present application, the resource update system of the application provided by the embodiments of the present application will be described below. Refer to Figure 1 , Figure 1 is a schematic architecture diagram of the resource update system of the application provided by the embodiments of the present application. To support an exemplary application, terminals (exemplarily showing terminals 400-1 and 400-2) are connected to the server 200 through the network 300. The network 300 can be a wide area network, a local area network, or a combination of both, and uses wireless or wired links to achieve data transmission.

[0088] Terminals (such as terminal 400-1 and terminal 400-2), which are installed with and run the client of the application program, are used to receive the update notification sent by the server during the running of the application program, download the update resource package corresponding to the application program from the server, store it in the local storage space (such as the SD card of the mobile terminal), and notify the process of the application program so that the process can obtain the update resource package from the local storage space.

[0089] Terminals (such as terminal 400-1 and terminal 400-2) are also used to obtain the update resource package of the application program during the running of the application program. The update resource package includes update resources and executable files. Based on the executable file, a plug-in class loader corresponding to the update resource package is created, and a class loader set including at least one non-plug-in class loader is generated. In the class loader chain corresponding to the application program, the host class loader is obtained, and the parent class loader of the host class loader is replaced with the plug-in class loader to obtain the target class loader chain. Based on at least one of the class loader set and the target class loader chain, the target class loader for loading the target class to which the update resource belongs is determined. The target class is loaded through the target class loader, and the function corresponding to the target class is run based on the update resource.

[0090] The server 200 is used to receive the update resource package of the application program uploaded by the development end during the running of the application program, and send an update notification to the terminals installed with the application program to notify each terminal that there is an update resource package for the application program. At the same time, it is also used to receive the download request for the application program update resource package sent by the terminal, and send the update resource package to the terminal (such as terminal 400-1 and terminal 400-2) that sends the download request.

[0091] In some embodiments, the server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery network (CDN, Content Delivery Network), and big data and artificial intelligence platforms. The terminal 400 can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a smart speaker, a smart watch, etc., but is not limited thereto. The terminal and the server can be directly or indirectly connected through wired or wireless communication methods, which are not limited in the embodiments of the present application.

[0092] The embodiments of the present application can be implemented with the help of cloud technology. Cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and networks within a wide area network or a local area network to realize the calculation, storage, processing, and sharing of data.

[0093] Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, be used on demand, and is flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources. With the highly developed application of the Internet industry, in the future, each item may have its own identification mark and needs to be transmitted to the background system for logical processing. Data at different levels will be processed separately, and various industry data requires the support of a powerful system. This can be achieved through cloud computing.

[0094] See Figure 2 , Figure 2 FIG. is a schematic structural diagram of an electronic device 500 for resource update of an application program provided by an embodiment of the present application. In actual applications, the electronic device 500 can be Figure 1 the server or terminal shown in FIG., taking the electronic device 500 as Figure 1 the domain name resolution node shown in FIG. as an example, the electronic device for resource update of the application program implementing the embodiment of the present application will be described. The electronic device 500 provided by the embodiment of the present application includes: at least one processor 510, a memory 550, at least one network interface 520, and a user interface 530. Each component in the electronic device 500 is coupled together through a bus system 540. It can be understood that the bus system 540 is used to realize the connection and communication between these components. In addition to the data bus, the bus system 540 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clear description, in Figure 2 all kinds of buses are labeled as the bus system 540.

[0095] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP, Digital Signal Processor), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor can be a microprocessor or any conventional processor, etc.

[0096] The user interface 530 includes one or more output devices 531 that enable the presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 530 also includes one or more input devices 532, including user interface components that assist the user in input, such as a keyboard, a mouse, a microphone, a touch screen display, a camera, and other input buttons and controls.

[0097] The memory 550 can be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard disk drives, optical disc drives, etc. The memory 550 optionally includes one or more storage devices that are physically remote from the processor 510.

[0098] The memory 550 includes volatile memory or non-volatile memory, and may also include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), and the volatile memory can be random access memory (RAM). The memory 550 described in the embodiments of the present application is intended to include any suitable type of memory.

[0099] In some embodiments, the memory 550 is capable of storing data to support various operations. Examples of such data include programs, modules, and data structures, or subsets or supersets thereof, which are illustrated below.

[0100] The operating system 551, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, driver layer, etc., for implementing various basic services and processing hardware-based tasks;

[0101] The network communication module 552 is used to reach other computing devices via one or more (wired or wireless) network interfaces 520. Exemplary network interfaces 520 include: Bluetooth, Wi-Fi (Wireless Fidelity), and USB (Universal Serial Bus), etc.;

[0102] The presentation module 553 is used to enable the presentation of information (such as a user interface for operating peripheral devices and displaying content and information) via one or more output devices 531 associated with the user interface 530 (such as a display screen, speaker, etc.).

[0103] The input processing module 554 is used to detect and translate one or more user inputs or interactions from one of one or more input devices 532.

[0104] In some embodiments, the resource update device of the application program provided by the embodiments of the present application can be implemented in software. Figure 2The resource update device 555 of the application program stored in the memory 550 is shown. It can be software in the form of programs and plugins, etc., and includes the following software modules: an acquisition module 5551, a generation module 5552, a replacement module 5553, a search module 5554, and a running module. These modules are logical, so they can be combined or further split arbitrarily according to the functions implemented. The functions of each module will be described below.

[0105] In some other embodiments, the resource update device of the application program provided in the embodiments of the present application can be implemented in a combination of software and hardware. As an example, the resource update device of the application program provided in the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the resource update of the application program provided in the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can adopt one or more application-specific integrated circuits (ASICs, Application Specific Integrated Circuits), DSPs, programmable logic devices (PLDs, Programmable Logic Devices), complex programmable logic devices (CPLDs, Complex Programmable Logic Devices), field-programmable gate arrays (FPGAs, Field-Programmable Gate Arrays), or other electronic components.

[0106] Based on the above description of the resource update system and electronic device of the application program provided in the embodiments of the present application, the resource update method of the application program provided in the embodiments of the present application will be described below. In some embodiments, the resource update method of the application program provided in the embodiments of the present application can be implemented independently by the server or the terminal, or implemented jointly by the server and the terminal. The resource update method of the application program provided in the embodiments of the present application will be described below taking the terminal implementation as an example.

[0107] See Figure 3 , Figure 3 is a schematic flowchart of the resource update method of the application program provided in the embodiments of the present application. The resource update method of the application program provided in the embodiments of the present application includes:

[0108] In step 101, during the running of the application program, the terminal acquires the update resource package of the application program, and the update resource package includes update resources and executable files.

[0109] In actual implementation, the application can be an Android desktop application based on the Android system (i.e., the system of the terminal is the Android system). The application is deployed on the terminal. During the running process of the application, the terminal can obtain the update resource package (also referred to as a plugin package, patch package, etc.) corresponding to the application through network download and other means to achieve hot deployment for the application. The hot deployment methods for the application include code repair, resource repair, etc. Among them, the principle of code repair is class replacement, which can be understood as using the classes in the update resource package to update the classes in the application. Here, the update can include using the classes in the update resource package to replace the classes that have been loaded in the application, and can also include adding the classes in the update resource package to the application. The replacement of classes is mainly achieved by the use of the classloader, and the dynamic loading of code is realized based on the classloader. The obtained update resource package is in the apk format, and the update resource package contains executable files. The Android virtual machine in the terminal dynamically loads various classes (dynamic loading of code) in the update resource package through the dex file.

[0110] In step 102, based on the executable file, a plugin classloader corresponding to the update resource package is created, and a classloader set including at least one non-plugin classloader is generated.

[0111] In actual implementation, the virtual machine of the terminal parses the executable file in the update resource package (such as the dex file of the Android system), and creates a classloader (i.e., the plugin classloader) for dynamically loading the code of the executable file (the code includes all classes included in the update of the application). At the same time, a classloader set corresponding to the non-plugin classloader is generated. The classloader set includes one or more non-plugin classloaders, and may also include the plugin classloaders of other plugins. It should be noted that the various classloaders in the classloader set are independent of each other and do not have a hierarchical relationship.

[0112] Exemplarily, taking the application as an Android application and the executable file as a dex file as an example, the dex file includes all classes of the update resource package, and each class contains its corresponding function method for implementing various functions of the application.

[0113] In step 103, in the classloader chain corresponding to the application, the host classloader is obtained, and the parent classloader of the host classloader is replaced with the plugin classloader to obtain the target classloader chain.

[0114] In actual implementation, since the loading of classes in the terminal is based on the parent delegation mechanism. That is, when loading a class through a class loader, there is a hierarchical class loader chain. The host class loader is a node on this class loader chain. When loading a class based on the host class loader, it will first be delegated to the parent class loader of the host class loader for loading (in the class loading process based on the parent delegation mechanism, the same class will not be loaded repeatedly, that is, each class is only loaded once). In order to preferentially load the updated resource package, the plugin class loader used to load the classes in the updated resource package can be directly used as the parent (class) loader of the host class loader. In this way, when running to the function corresponding to the updated resource package, the plugin class loader will be preferentially used for loading.

[0115] First, obtain the class loader of the running application (i.e., the host class loader) and the class loader chain in which the host class loader is located. The class loader chain is composed of multiple class loaders, and there is a parent-child relationship between adjacent class loaders. Each class loader is used to implement the loading of different types of classes. The implementation process can be to call the getClassLoader method of the class provided by the Android system to obtain the class loader of the running application (host class loader), and then call the getParent method provided by the system class loader to obtain the parent (class) loader of the host class loader and the class loader chain containing the host class loader. There is a hierarchical relationship among the class loaders in the class loader chain. Among them, the topmost is the system class loader.

[0116] Exemplarily, taking the loading of the updated resource package in the Android system as an example, the class loader chain for loading the classes of the application is BaseClassLoader (application class loader) -> BootClassLoader (boot class loader), that is, the parent class loader of BaseClassLoader is BootClassLoader. Taking the loading of the updated resource package in the Java system as an example, the class loader chain for loading the classes of the application is UserClassLoader (user-defined class loader) -> Application ClassLoader (application class loader) -> ExtentionClassLoader (extension class loader) -> BootstrapClassLoader (boot class loader).

[0117] In step 104, based on at least one of the class loader set and the target class loader chain, determine the target class loader for loading the target class to which the updated resource belongs.

[0118] In actual implementation, according to the parent delegation mechanism of the class loader, the system preferentially uses the class loader at the parent level in the class loader chain of the host loader for class loading. If the parent class loader can complete the class loading task, it will return successfully. If the parent class loader cannot complete the loading task, the child loader will try to load it by itself. The parent class loader distributes tasks layer by layer downwards. If the child class loader can load, it will load this class. If the loading task is assigned to the system class loader and this class still cannot be loaded, an exception will be thrown (such as an exception or crash when a certain function of the application is used). Based on this, in order to ensure the normal operation of the program, the class loader used to load the classes in the updated resource package can be found in the set of class loaders corresponding to the plugin class loader, so as to avoid crashes when the application runs to the corresponding function.

[0119] In some embodiments, referring to Figure 4 , Figure 4 is the determination method of the target class loader provided by the embodiments of the present application. Based on Figure 3 , step 104 can be implemented through steps 1041-1042:

[0120] Step 1041, the terminal determines the target class loader for loading the target class to which the updated resource belongs based on the class loaders corresponding to each node in the target class loader chain.

[0121] Among them, the class loaders in the target class loader chain have a hierarchical relationship.

[0122] In actual implementation, the class loading process is based on the parent delegation mechanism. The parent class loader of the host class loader in the target class loader chain is the plugin class loader corresponding to the updated resource package. During the operation of the application, when the host loader receives a class loading request for at least one class used in the updated resource package, it preferentially delegates it to the plugin class loader for execution. If the plugin class loader still has a parent class loader in the target loader chain, it will be further delegated upwards recursively until the request reaches the topmost bootstrap class loader. If the parent class loader can complete the class loading task, it will return successfully. At this time, this parent class loader is the target class loader for loading the target class to which the updated resource belongs.

[0123] In some embodiments, referring to Figure 5 , Figure 5 is the flowchart of the method for determining the target class loader based on the target class loader chain provided by the embodiments of the present application. Combined with Figure 5 the steps 201a-204a shown are described as follows:

[0124] Step 201a, based on the hierarchical relationship between the class loaders in the target class loader chain, determine the sub-hierarchical relationship with the plugin class loader as the lowest level.

[0125] In actual implementation, there is a hierarchical relationship among the class loaders in the target class loader chain, that is, the child class loader of the plug-in class loader is the host class loader, and the hierarchical relationship with the plug-in class loader as the lowest level is determined. In this way, when the host class loader receives a class loading request for a class included in the updated resource package, it will directly delegate the class loading request to the plug-in class loader in the hierarchical relationship for execution. Based on the parent delegation mechanism, the plug-in class loader determines the class loaders of various classes in the updated resource package.

[0126] Step 202a: Starting from the plug-in class loader, obtain the class loading paths of the class loaders at each level in the hierarchical relationship.

[0127] In actual implementation, each class loader corresponds to a class loading path that can be loaded, which is used to represent the class path of the classes that the current class loader can load. The terminal parses the executable file in the update package to determine the class loading path of the classes applied in the updated resource package, and matches it with the class loading paths of the class loaders at each level in the hierarchical relationship. In this way, the class loader corresponding to the class referenced by the updated resource package can be determined.

[0128] Step 203a: Obtain the target class loading path of the target class, and compare the target class loading path with various class loading paths to obtain a comparison result.

[0129] In actual implementation, the class path of the class to be loaded is matched with at least one class loading path in the class loader. When the match is successful, it can indicate that the class to be loaded has been loaded by the current class loader, and the class to be loaded will not be loaded again without restarting the application.

[0130] Step 204a: When the comparison result indicates that the target class loading path is different from any class loading path, use the plug-in class loader as the target class loader of the target class.

[0131] In actual implementation, the target class loading path is compared with the class loading paths corresponding to various class loaders included in the hierarchical relationship. When the target class loading path is different from any class loading path, it means that the target class has not been loaded in the currently running application. At this time, use the plug-in class loader as the class loader of the target class to load the target class.

[0132] Step 1042: When the target class loader cannot be determined based on the target class loader chain, determine the target class loader based on the class loaders in the class loader set.

[0133] Among them, the class loaders in the class loader set do not have a hierarchical relationship.

[0134] In actual implementation, when the plug-in class loader serves as the target class loader of the target class, if the plug-in class loader cannot load the target class, it indicates that the target class is a class in other update package resources or a class already installed in the application. To avoid program crashes, the class loader used to load the target class can be searched in the class loader set corresponding to the plug-in class loader. The class loader set corresponding to the plug-in class loader includes the host class loader other than itself and other class loaders. It should be noted that the host class loader in the class loader set is used to preferentially load relevant classes in the update resource package. In this way, the problem that classes cannot be loaded can be effectively avoided.

[0135] In some embodiments, refer to Figure 6 , Figure 6 which is the flowchart of the method for determining the target class loader based on the class loader set provided by the embodiments of the present application. The following is an explanation in combination with Figure 6 the steps 201b - 203b shown:

[0136] Step 201b, the terminal obtains the class loading paths of various class loaders in the class loader set.

[0137] In actual implementation, when the target class loader cannot be determined based on the various class loaders in the target class loader chain, the target class loader set can continue to be searched based on the class loader set. The role of the class loader set is that when the target class loader cannot be determined in the target class loader chain based on the parent delegation mechanism, the target class loader can be searched again in the class loader set, so as to determine the target class loading and achieve the loading of the target class, avoiding situations such as crashes during the operation of the application. Therefore, the terminal obtains the class loading paths that can be loaded by various class loaders in the class loader set to complete the search process based on the class loading paths.

[0138] Step 202b, obtain the target class loading path of the target class, and search for the target class loading path in the class loading paths of various class loaders to obtain a search result.

[0139] In actual implementation, the terminal obtains the class loading paths of various class loaders in the class loader set and searches for the target class loading path in various class loading paths.

[0140] Step 203b, when the search result indicates that there is a target class loading path in the class loading paths of various class loaders, use the class loader to which the class loading path belongs as the target class loader.

[0141] In actual implementation, the class loading path of the target class is matched with the class loading paths corresponding to the class loaders in the class loader set, and the class loader corresponding to the class loading path that is the same as the target class loading path is used as the target class loader. It should be noted that the class loading path may include information such as class names and class identifiers. If the class name of the target class is the same as the class name in the current class loading path, it does not mean that the class loading class path of the target class matches the current class loading path.

[0142] In some embodiments, referring to Figure 7 , Figure 7 is the flowchart of the method for determining the target class loader based on the type of the target class provided by the embodiments of the present application. Based on Figure 3 , step 104 can be implemented through steps 1041b - 1044b:

[0143] Step 1041b, the terminal identifies the type of the target class whose resource attribution is updated, and the type includes a host class and a plug-in class.

[0144] Among them, the host class is the class loaded by the host class loader when installing the application program, and the plug-in class is the class loaded by the plug-in class loader when running the application program.

[0145] In actual implementation, in order to improve the search efficiency for the target class loader, the type of the target class can be determined first, and based on the type, it is judged whether to use the target class loader chain to determine the target class loader or use the class loader set to determine the target class loader. In this way, there is no need for secondary search, and the efficiency of determining the target class loader can be effectively improved. It should be noted that the types of classes can be divided into host classes and plug-in classes. Among them, the host class can be understood as the class loaded by the host class loader when installing the application program, and the plug-in class can be understood as the class loaded by the plug-in class loader when running the application program.

[0146] Step 1042b, when the type is a host class, determine the target class loader for loading the target class from at least one non-plug-in class loader in the class loader set.

[0147] In actual implementation, when the type is a host class, the target class loader can be directly determined in the class loader set corresponding to the plug-in class loader. In this way, it is not necessary to search among the class loaders in the target class loader chain, effectively improving the search efficiency.

[0148] Step 1043b, when the type is a plug-in class, obtain the set of reference class identifiers corresponding to the plug-in class loader, where the reference class identifier is the class identifier of other classes referenced in the plug-in class loader.

[0149] In actual implementation, when the type is a plug-in class, it is also necessary to further determine the target class loader according to the class identifier of the target class. That is, the terminal further determines whether to determine the target class loader based on the target class loader chain where the plug-in class loader is located or use other plug-in class loaders in the class loader set according to the class identifier of the target class.

[0150] Step 1044b: Determine the target class loader for loading the target class based on one of the class loader set and the target class loader chain, and the reference class identifier set.

[0151] In actual implementation, according to the reference class identifiers in the reference class identifier set, determine the target class loader from the class loader set or the target class loader chain.

[0152] In some embodiments, the terminal can determine the target class loader based on the type of the target class in the following manner: The terminal matches the class identifier of the target class with each class identifier in the reference class identifier set to obtain a matching result; when the matching result indicates that the class identifier of the target class belongs to the reference class identifier set, determine the target class loader for loading the target class based on the class loader set; when the matching result indicates that the class identifier of the target class does not belong to the reference class identifier set, determine the target class loader for loading the target class based on the target class loader chain.

[0153] In actual implementation, first match the class identifier of the target class with each class identifier in the reference class identifier set. If the class identifier of the target class can be found in the reference class identifier set, it indicates that the target class is a reference class of the class parsed from the executable file and cannot be loaded through the plug-in class loader.Therefore, determine the target class loader for loading the target class based on the class loader set corresponding to the plug-in class loader; if the class identifier of the target class cannot be found in the reference class identifier set, it indicates that the target class is not a reference class, and then the target class loader can be determined from the target class loader chain corresponding to the plug-in class loader.

[0154] In step 105, load the target class through the target class loader and run the function corresponding to the target class based on the updated resources.

[0155] In actual implementation, by using the target class loader chain that adopts the parent delegation mechanism and the class loader set corresponding to the plug-in class loader, the target class loader for loading the class corresponding to the updated resource is determined, and the class corresponding to the updated resource is loaded based on the target class loader, so as to implement the hot fix operation for the code of the application program. And based on the resource manager corresponding to the application program, the updated resource is loaded into the memory allocated by the terminal for the application program, so as to implement the hot deployment of the resources of the application program. It can be understood that based on the updated resource package, the hot update or hot deployment of the application program is realized. After the server of the application program issues a plug-in resource package, after the terminal downloads the resource package, it notifies the application process of the application program through broadcasting. After receiving the broadcast notification, the application process loads the corresponding resource package through the class loader. The specific steps are as follows: The terminal copies the updated resource package to the specified plug-in installation directory allocated for the application program; the updated resource package is loaded by reflecting the add resource method of the resource manager; the class corresponding to the updated resource is loaded by the way of the parent delegation mechanism (i.e., the target class loader chain) and the custom class loader list (i.e., the class loader set) adopted during class loading; by adjusting the node (class loader chain) of the parent delegation chain where the host class loader is located, the parent node of the host class loader is dynamically replaced during the running of the application program, that is, the parent class of the host class loader is replaced with the plug-in class loader, so as to complete the automatic effect taking of the updated resource package of the application program, and the entire update process does not require restarting the process of the application program.

[0156] In some embodiments, referring to Figure 8 , Figure 8 is the flowchart of the resource loading method for the updated resource provided by the embodiment of the present application. Based on Figure 3 , after step 105, the following can also be executed:

[0157] Step 301, the terminal obtains the resource loading path of the updated resource and the resource loader of the application program.

[0158] In actual implementation, after the terminal obtains the updated resource package, it obtains the resource loading path of the updated resource in the updated resource package, and the updated resource is the resource that needs to be added or replaced in the application program.

[0159] Exemplarily, taking the Android system as an example, the Android resources are loaded by using the resource manager AssetManager, and then the resources are referenced and parsed through the resource identifiers in the class.

[0160] Step 302, insert the resource loading path before the original resource loading path of the application program in the resource loader to obtain the target resource loading path.

[0161] In actual implementation, in order to be able to preferentially load updated resources, a resource loading path can be inserted before the original resource loading path of the application in the resource loader. In this way, it can be ensured that

[0162] Step 303: Load the updated resources into the memory space of the application according to the loading order indicated by the target resource loading path.

[0163] In actual implementation, similar to class loading, the Android virtual machine performs resource loading according to the loading order indicated by the modified resource loading path (first the updated resources, and then the resources corresponding to the original application), so as to add resources to the original application or replace the resources in the original application.

[0164] In the above manner, by inserting the resource loading path of the updated resources before the resource loading path of the original application, when the system virtual machine performs resource loading, it preferentially loads the updated resources in the updated resource package, so as to add resources to the original application or replace the resources in the original application.

[0165] In some embodiments, referring to Figure 9 , Figure 9 is the flowchart of the method for loading the target class and updated resources provided by the embodiments of the present application. Based on Figure 3 , after step 105, the following can also be executed:

[0166] Step 401: When the terminal can determine the target class loader of the target class based on at least one of the class loader set and the target class loader chain, obtain the class loading path of the target class.

[0167] In actual implementation, after determining the target class loader of the target class, the loading operation of the target class is realized by determining the class loading path of the target class.

[0168] Step 402: Control the target class loader to perform the loading operation on the target class based on the class loading path.

[0169] In actual implementation, the terminal controls the target class loader and uses the class loading path of the target class as a parameter to realize the loading operation on the target class.

[0170] Exemplarily, in the Android system, for the loading of the target class A, the Android system calls the loadClass method in the target class loader classloader to realize the loading of the target class. Among them, the parameter of the loadClass method is the class loading path of the target class A.

[0171] Step 403: During the execution of the loading operation, obtain the updated resources from the memory space of the application based on the resource identifier of the updated resources.

[0172] In actual implementation, when performing a loading operation on a class corresponding to an updated resource, if there is a reference to the resource in the class, the updated resource can be obtained from the memory space of the application according to the resource identifier of the updated resource.

[0173] Step 404, when the loading operation is completed, based on the updated resource, run the function corresponding to the target class after the resource is updated.

[0174] In actual implementation, the terminal controls the process of the application. After dynamically loading various classes in the updated resource package according to the integrity of the executable file, combined with the parent delegation mechanism, when performing class loading, the various classes in the updated resource package are preferentially loaded. At the same time, according to the resource loading paths of the various updated resources in the updated resource package and the reference situations of the various updated resources based on the resource identifiers in the updated resource package, the update of the resources is completed, so as to complete the hot deployment of the application based on the updated resource package.

[0175] In some embodiments, when the target class loader corresponding to the target class is not determined, the terminal can also display an error prompt message: when the target class loader of the target class cannot be determined based on at least one of the class loader set and the target class loader chain, control the plug-in class loader to capture the exception information, and generate an error prompt message based on the exception information; when running the function corresponding to the target class, display the error prompt message; wherein, the error prompt message is used to indicate that the update operation of the application based on the updated resource package fails.

[0176] In actual implementation, when the class loader corresponding to the target class cannot be determined based on the target class loader chain or the class loader set, the plug-in class loader corresponding to the updated resource package will capture the exception information that the corresponding class fails to be loaded successfully or the class loader cannot be found, and display the error prompt message in a visual way.

[0177] Exemplarily, taking the Android system as an example, when the plug-in class loader catches the exception that the class is not found, an error prompt message such as "Function A is being improved" can be popped up on the interface of the application.

[0178] In some embodiments, refer to Figure 10 , Figure 10 is the flowchart of the method for obtaining the updated resource package of the application provided by the embodiment of the present application. Based on Figure 3 , after step 105, the following can also be executed:

[0179] Step 501, during the running process of the application, the terminal receives an update notification sent by the server, and the update notification is used to indicate that there is an updated resource package for the application.

[0180] In actual implementation, during the running of the application, it can receive update notifications sent by the server in real time. Additionally, the application can also actively send an update request to the server to request an update resource package from the server.

[0181] Exemplarily, when the terminal is running Application A, the terminal displays "There is an update for the current application. Do you want to update?", and when the user selects to update, it sends an update request for Application A to the server.

[0182] Step 502: Download the update resource package to the local storage space according to the update notification.

[0183] In actual implementation, the terminal downloads the update resource package of the application from the server to the local storage space according to the received update notification. For example, an Android terminal downloads the update package of the application to the local memory card.

[0184] Step 503: Notify the process of the application so that the process can obtain the update resource package from the local storage space.

[0185] In actual implementation, after the terminal downloads the update resource package of the application to the local, it controls the process running the application to obtain the update resource package downloaded from the server from the local storage space.

[0186] In some embodiments, refer to Figure 11 , Figure 11 which is the flowchart of the method for obtaining the update resource package of the application provided by the embodiments of the present application. Based on Figure 3 , after step 105, the following steps can also be executed:

[0187] Step 601: The terminal parses the executable file to obtain at least one class to be loaded included in the update resource package.

[0188] In actual implementation, for a running application, one update may involve multiple different functional modules being updated. That is, the update resource package includes various classes to be loaded, and one class to be loaded can represent a functional module, that is, one functional module corresponds to one class to be loaded.

[0189] Exemplarily, taking an Android application as an example, during the running of Application A, when running to Function B, the terminal detects the update resource package for Function B sent by the server. The Android system parses the update resource package to obtain class a to be loaded, class b to be loaded, and class c to be loaded. Among them, class a to be loaded references class b to be loaded and class c to be loaded, and class a to be loaded, class b to be loaded, and class c to be loaded respectively correspond to different functions.

[0190] Step 602: Create a plugin class loader for loading at least one class to be loaded.

[0191] In actual implementation, the terminal creates a plug-in class loader for loading classes to be loaded, which is used to implement the loading operations for various classes in the updated resource package.

[0192] Continuing with the above example, the Android system creates plug-in class loaders 1, 2, and 3 for loading the class a to be loaded, the class b to be loaded, and the class c to be loaded.

[0193] Step 603: Obtain at least one non-plug-in class loader corresponding to the application program, and generate a class loader set including at least one non-plug-in class loader and other plug-in class loaders except the plug-in class loader.

[0194] Continuing with the above example, when loading the class a to be loaded through the plug-in class loader 1, the target class loader chain corresponding to the class a to be loaded is determined based on the plug-in class loader 1, and at the same time, a class loader set S corresponding to the plug-in class loader 1 is generated. S includes all class loaders required during the operation of other application programs except the plug-in class loader 1, such as the plug-in class loader 2, the plug-in class loader 3, etc. Among them, each class loader is independent of each other and does not have a hierarchical relationship.

[0195] Applying the embodiments of the present application, during the operation of the application program, a plug-in class loader corresponding to the updated resource package is created, and the parent class loader of the host class in the class loader chain of the application program is replaced with the plug-in class loader to obtain the target class loader chain. In this way, it can be ensured that when updating resources, the plug-in class loader is preferentially used to load the target class to which the updated resources belong; at the same time, combining the target class loader chain and the class loader set to determine the target class loader can ensure the accuracy of determining the target class loader and improve the search efficiency of the target class loader; using the target class loader to load the target class and running the functions associated with the updated resources can, in this way, realize the dynamic replacement of the resource identifier by dynamically replacing the class loader during the program operation, thereby realizing the update of resources without restarting the application process.

[0196] Next, an exemplary application of the embodiments of the present application in an actual application scenario will be described.

[0197] In the industry, only the cold start of resources takes effect in the resource dynamicization of Android plug-ins. For example, existing hot fix and hot update solutions in the industry must restart the APP to achieve repair. The "hot" in hot fix and hot update means that there is no need to perform a full package upgrade of the APP. Bug repair can be achieved directly by downloading the repair package and then restarting the APP. The "hot" in our hot deployment means that the APP neither needs a full package upgrade nor needs to be restarted to achieve repair. After the resource dynamicization upgrade, the current process must be killed and restarted to make the new resources take effect. During the face recognition payment process on mobile terminals, since it is an application scenario for business-oriented (ToB) APPs, the app process exists 24 hours a day. If the app needs to be restarted due to resource dynamicization, it will have an impact on the face recognition payment process. For example, the process restart requires re-initialization, which will slow down the speed of the first face recognition. Moreover, the process restart may interrupt the merchant's payment and cashiering, making the merchant aware of the change in our face recognition application and causing trouble to the merchant.

[0198] Based on this, the embodiment of the present application provides a method for updating an application program, which is a solution that can make the resource dynamicization take effect without process restart in this special business scenario, that is, a hot deployment effect solution at the resource level of the Android terminal.

[0199] Next, the method for updating an application program provided by the embodiment of the present application (that is, the hot deployment effect at the resource level) will be specifically described.

[0200] In actual implementation, the resources in the Android system are loaded by the resource manager (AssetManager), and then in the code (class) implementation, the resources are referenced and parsed through the resource identifier (used to represent the uniqueness of the resource). Therefore, for resource dynamicization update (i.e., resource hot deployment), on the one hand, the updated resources in the updated resource package can be loaded through the resource manager (such as pictures, files, animations, etc.). On the other hand, since the field hot deployment in the implementation code takes effect, in addition to loading the updated resource package into the memory, the reference to the old resource identifier in the code also needs to be dynamically replaced. Therefore, in actual applications, the method of loading classes by an independent class loader (plug-in class loader) can be used to dynamically replace the resource identifier in the code (i.e., achieve code repair through the plug-in class loader). By combining the above two methods, the hot deployment of Android resources can take effect. That is to say, to implement the method for updating an application program provided by the embodiment of the present application, at least two functional modules are included: 1) Based on the resource manager, load the updated resources, that is, load the resources in the updated resource package into the terminal memory through the resource manager; 2) Based on the independent class loader, load the classes in the updated resource package, that is, dynamically replace the resource identifier referenced by the code in the updated resource package through the independent class loader.

[0201] Next, based on the resource manager, the process of loading updated resources will be described. That is, the updated resources in the updated resource package are loaded into the terminal memory through the resource manager. In actual implementation, refer to Figure 12 , Figure 12 is a schematic flow chart for loading updated resources provided in the related art. In the figure, the process of loading updated resources is as follows: The terminal executes Step 1. Re-create a new resource manager AssetsManager object through reflection, and then execute Step 2. Invoke the resource loading interface of AssetsManager through reflection. Then execute Step 3. Load the corresponding plugin resources (i.e., updated resources, such as the resources of the host apk, the resources of the split apk, and the resources of the plugin apk) into the storage space by calling the AssetManager.addAssetPath method; then execute Step 4. Determine whether the resource package has been loaded. If so, execute Step 4.1 without reloading and directly return the index of the loaded resource package. If not, execute Step 4.2. If the loading is successful, return the resource package index, and then execute Step 5. Reflect the ResourcesManager system class, the LoadedApk class, and the Context system class respectively. Finally, execute Step 6. Update the Resources object in ResourcesImpl, the Resources object in LoadedApk, and the Resources object in Context respectively. That is to say, Figure 11 in the related art, resource update is performed by replacing the Resources objects maintained in the context Context, LoadedApk, and ResourcesManager in the running application. This method cannot ensure that all Resources objects are updated (i.e., the update is one-sided), and only ensures the update of the Resources objects in these three places: Context, LoadedApk, and ResourcesManager.

[0202] Based on this, refer to Figure 13 , Figure 13It is a schematic flowchart of the process for loading updated resources provided by an embodiment of this application. By analyzing the source code of the ResourcesManager class, it can be determined that all Resources objects in the application are saved in ResourcesManager (such as ResourcesImpl, ResourcesRef, ActivityResourcesRef). By traversing these attributes of Resources, all AssetManager objects can be obtained, and then the updated resources are added as plug-in resources through the addAssetPath method of AssetManager. Therefore, based on Figure 12 the resource loading method in Figure 13 Steps 1-4 are the same as those in Figure 12 Starting from step 5, the modified resource loading method is that the terminal executes step 5. Reflect the ResourcesManager system class without reflecting other system classes. In this way, the system overhead can be reduced and the performance can be improved. Then execute step 6. Obtain all ResourcesManager objects, and then execute step 7. Call the AssetManager.addAssetPath method to load all ResourcesManager objects.

[0203] Next, the process of loading classes in the updated resource package based on an independent class loader will be described. That is, based on the independent class loader, the resource identifiers referenced in the code are dynamically replaced. See Figure 14 , Figure 14 is a flowchart of the resource loading reference method provided in the related art. In the figure, taking the resource loading in the Android system as an example, in the Android system, the resources are loaded through step 1. AssetManager, then step 2. Call the application class loader BaseClassLoader to load the class, and then step 3. Search for the referenced resource identifier (ID) in the class code. After finding the resource identifier, execute step 4. Obtain the already loaded resources in AssetManager according to the resource identifier, and finally execute step 5. Parse and use the resources. In actual implementation, based on Figure 14 the resource loading reference method implemented needs to replace the resource identifiers one by one. The granularity of the resource identifiers is too small, which consumes a large amount of computing resources of the system and may cause abnormalities in other functions. That is to say, replacing the resource identifiers is not feasible, and even replacing them at the class granularity is not feasible.

[0204] Based on this, see Figure 15 , Figure 15It is a flowchart of the resource loading and reference method provided by the embodiment of the present application. In this method, the dynamic replacement class is modified to the dex where the dynamic replacement class is located, and the dynamic loading of the third-party dex provided by the Android system is used to realize the dynamic replacement of the dex, and then the dynamic replacement of the class (Class) and the dynamic replacement of the resource identifier are realized. In the figure, taking the resource loading in the Android system as an example, in the Android system, the resource is loaded through step 1. AssetManager, then step 2. is executed to call the third-party class loader to load the class, and then step 3. is executed to determine whether the class is successfully loaded. If the class cannot be found, downgraded loading is performed, that is, step 4. is executed to call BaseClassLoader to load the class, and then step 5. is executed to find the resource identifier from the replaced class; if it is determined in step 3 that the loading is successful, then step 6. is executed to find the resource identifier from the new class. Finally, based on the target resource identifier found in step 5 or 6, step 7. is executed to obtain the already loaded resource in AssetManager according to the resource identifier.

[0205] In actual implementation, the loading of classes is implemented using the parent delegation mechanism, that is, when the current class loader receives a class loading request for a class, it first delegates it to its parent class for loading. Based on this, in order to be able to preferentially load the classes corresponding to the updated resource package, an independent class loader can be created and this independent class loader can be used as the parent class loader of the current class loader. Specifically, see Figure 16 , Figure 16 It is a flowchart of the method for dynamically loading classes provided by the embodiment of the present application. The process of dynamically loading classes in the figure is as follows: The system executes step 1. to start the application, step 2. to create an application class loader BaseClassLoader for loading classes, and step 3. to load the classes in the application through BaseClassLoader. During the running of the application, when a new class is dynamically loaded, step 4. is executed to create a new class loader ClassLoader, step 5. is executed to load the new class through the new ClassLoader, step 6. is executed to determine the parent node (i.e., the parent class loader) of BaseClassLoader, and then step 7. is executed to set the parent node of BaseClassLoader to the newly created ClassLoader, and then step 8. is executed to set the original parent node of BaseClassLoader to the parent node of the newly created ClassLoader. Through the replacement of the parent class loader as described above, the dynamic loading of classes is realized. In this way, it can be ensured that the information in the updated resource package is always preferentially loaded.

[0206] In actual implementation, see Figure 17 , Figure 17It is a flowchart of the class loading method provided in the related art. In the figure, for the class loading method adopting the parent delegation mechanism, when starting to execute step 1, when the application class loader BaseClassLoader receives a class loading request for a class, step 2 is executed. It is judged whether it has loaded this class before. If so, step 5 is executed to indicate that the class loading is successful; if not, step 3 is executed, and it is delegated to its parent class loader BootClassLoader (the class loader corresponding to the startup class) for loading. Step 4 is executed to judge whether BootClassLoader has loaded this class before. If so, step 5 is executed to indicate that the class loading is successful; if not, step 6 is executed to indicate that the Class loading fails for the class loader corresponding to the application program. In actual implementation, based on Figure 17 In the way of, if only the parent delegation is used to load the plugin Class, it is possible to load the plugin class in the host apk, but it is impossible to load the host class in the plugin apk, and it is impossible to load the classes of other plugins in the plugin apk. Therefore, a ClassNotFoundException exception will be encountered, and naturally it is impossible to achieve the effect of hot deployment. Based on this, see Figure 18 , Figure 18 It is a flowchart of the class loading method for the classes referred to in the updated resource package provided by the embodiment of the present application. In the figure, each third-party class loader ClassLoader serves as a node in the parent delegation class loader chain. First, the class is loaded through the parent delegation mode. If it cannot be loaded, a class loader set (including the application class loader BaseClassLoader, the third-party class loader 1, the third-party class loader 2, etc.) will be saved in the third-party class loader. Then, the ClassNotFoundException will be caught in the third-party class loader, and the loading will be degraded to continue loading the class in the class loader set. In this way, it is possible to load the classes of each other arbitrarily between the host apk and the plugin apk; through this class loading mechanism, we have achieved dynamic replacement of the resource ID, and the method of dynamically replacing the parent of the ClassLoader does not require restarting to take effect. Therefore, the new resource ID here also does not require restarting to take effect, achieving the effect of hot deployment of the resource ID. Combining with the addAssetPath interface of AssetManager to realize dynamic loading of the resource package into the memory, the hot deployment of Android resources is realized as a whole.

[0207] In actual implementation, when multiple updated resource packages are updated, the class loader used to load the resource package to be updated can be used as the parent (class) loader of the current loader of the application program. See Figure 19 , Figure 19It is a schematic diagram of a method for dynamically loading classes based on multiple update resource packages provided by an embodiment of this application. In the figure, there are two class loaders corresponding to the update resource packages, namely the third-party ClassLoader1 and the third-party ClassLoader2. First, replace the parent class loader of BaseClassLoader with the third-party ClassLoader1 to implement the deployment for update resource package 1, and then continue to replace the parent class loader of BaseClassLoader with the third-party ClassLoader2 to implement the deployment for update resource package 2. The entire process does not require restarting the process. Only by replacing the ClassLoader of the parent can the resource update take effect.

[0208] In the above embodiment, the dynamic replacement of Dex is achieved by combining the parent delegation loading based on an independent ClassLoader and the caching list ClassLoader, thereby achieving the dynamic replacement of resource IDs, and enabling the hot deployment of Android resources to take effect without restarting the process.

[0209] Applying the embodiment of this application, when the terminal needs to change Android resources, there is no need to upgrade the entire package of the APK. Instead, directly send a resource package that needs to be updated (which can include pictures, layout configurations, etc.). The terminal downloads the resource package and then loads the resource package through the above solution, enabling the APP process of the terminal to achieve dynamic resource updates without restarting.

[0210] It can be understood that in the embodiment of this application, data related to user information, etc. is involved. When the embodiment of this application is applied to specific products or technologies, user permission or consent needs to be obtained, and the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards of relevant countries and regions.

[0211] Next, continue to describe the implementation of the resource update device 555 of the application provided by the embodiment of this application as an exemplary structure of software modules. In some embodiments, as Figure 2 shown, the software modules stored in the resource update device 555 of the application in the memory 550 may include:

[0212] An acquisition module 5551, configured to acquire the update resource package of the application during the running of the application, where the update resource package includes update resources and executable files;

[0213] A generation module 5552, configured to create a plugin class loader corresponding to the update resource package based on the executable file, and generate a class loader set including at least one non-plugin class loader;

[0214] A replacement module 5553, which is used to obtain a host class loader in the class loader chain corresponding to the application program, and replace the parent class loader of the host class loader with the plug-in class loader to obtain a target class loader chain;

[0215] A search module 5554, which is used to determine a target class loader for loading a target class to which the updated resource belongs based on at least one of the class loader set and the target class loader chain;

[0216] An execution module 5555, which is used to load the target class through the target class loader and execute the function corresponding to the target class based on the updated resource.

[0217] In some embodiments, the search module is further configured to determine a target class loader for loading a target class to which the updated resource belongs based on the class loaders corresponding to each node in the target class loader chain; when the target class loader cannot be determined based on the target class loader chain, determine the target class loader based on the class loaders in the class loader set; wherein, the class loaders in the target class loader chain have a hierarchical relationship, and the class loaders in the class loader set do not have a hierarchical relationship.

[0218] In some embodiments, the search module is further configured to determine a sub-hierarchical relationship with the plug-in class loader as the lowest level based on the hierarchical relationship between the class loaders in the target class loader chain; starting from the plug-in class loader, obtain the class load paths of the class loaders at each level in the sub-hierarchical relationship; obtain the target class load path of the target class, and compare the target class load path with each of the class load paths to obtain a comparison result; when the comparison result indicates that the target class load path is different from any of the class load paths, use the plug-in class loader as the target class loader of the target class.

[0219] In some embodiments, the search module is further configured to obtain the class load paths of the class loaders in the class loader set; obtain the target class load path of the target class, and search for the target class load path in the class load paths of the class loaders to obtain a search result; when the search result indicates that the target class load path exists in the class load paths of the class loaders, use the class loader to which the class load path belongs as the target class loader.

[0220] In some embodiments, the search module is further configured to identify the type of the target class to which the updated resource belongs, and the type includes a host class and a plug-in class; wherein, the host class is a class loaded by the host class loader when the application program is installed, and the plug-in class is a class loaded by the plug-in class loader when the application program is running;

[0221] In some embodiments, the lookup module is further configured to, when the type is a host class, determine a target class loader for loading the target class from at least one non-plugin class loader in the class loader set; when the type is a plugin class, obtain a set of reference class identifiers corresponding to the plugin class loader, and determine a target class loader for loading the target class based on one of the class loader set and the target class loader chain and the set of reference class identifiers; wherein, the reference class identifier is the class identifier of other classes referenced in the plugin class loader.

[0222] In some embodiments, the lookup module is further configured to match the class identifier of the target class with each class identifier in the set of reference class identifiers to obtain a matching result; when the matching result indicates that the class identifier of the target class belongs to the set of reference class identifiers, determine a target class loader for loading the target class based on the class loader set; when the matching result indicates that the class identifier of the target class does not belong to the set of reference class identifiers, determine a target class loader for loading the target class based on the target class loader chain.

[0223] In some embodiments, the running module is further configured to obtain the resource loading path of the updated resource and the resource loader of the application; insert the resource loading path before the original resource loading path of the application in the resource loader to obtain a target resource loading path; and load the updated resource into the memory space of the application according to the loading order indicated by the target resource loading path.

[0224] In some embodiments, the running module is further configured to, when it is possible to determine the target class loader of the target class based on at least one of the class loader set and the target class loader chain, obtain the class loading path of the target class, and control the target class loader to perform a loading operation on the target class based on the class loading path; during the execution of the loading operation, obtain the updated resource from the memory space of the application based on the resource identifier of the updated resource, and when the loading operation is completed, run the function corresponding to the target class after the resource update based on the updated resource.

[0225] In some embodiments, the running module is further configured to, when the target class loader of the target class cannot be determined based on at least one of the class loader set and the target class loader chain, control the plug-in class loader to capture exception information, and generate an error prompt message based on the exception information; and display the error prompt message when running the function corresponding to the target class; wherein the error prompt message is used to indicate that the update operation of the application program based on the updated resource package fails.

[0226] In some embodiments, the obtaining module is further configured to, during the running of the application program, receive an update notification sent by the server, where the update notification is used to indicate that there is an updated resource package for the application program; download the updated resource package to the local storage space according to the update notification, and notify the process of the application program, so that the process obtains the updated resource package from the local storage space.

[0227] In some embodiments, the generating module is further configured to parse the executable file to obtain at least one class to be loaded included in the updated resource package; create a plug-in class loader for loading the at least one class to be loaded; obtain at least one non-plug-in class loader corresponding to the application program, and generate a class loader set including the at least one non-plug-in class loader and other plug-in class loaders except the plug-in class loader.

[0228] An embodiment of the present application provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the resource update method of the application program in the above embodiments of the present application.

[0229] An embodiment of the present application provides a computer-readable storage medium storing executable instructions, where the executable instructions, when executed by a processor, will cause the processor to execute the resource update method of the application program provided by the embodiment of the present application. For example, Figure 3 the resource update method of the application program shown.

[0230] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface memory, optical disc, or CD-ROM; or may be various devices including one or any combination of the above memories.

[0231] In some embodiments, the executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including being deployed as a stand-alone program or being deployed as a module, component, subroutine, or other unit suitable for use in a computing environment.

[0232] As an example, the executable instructions may or may not correspond to a file in a file system, may be stored as part of a file that holds other programs or data, for example, in one or more scripts in a Hyper Text Markup Language (HTML) document, stored in a single file dedicated to the program being discussed, or, stored in multiple cooperating files (e.g., files that store one or more modules, subroutines, or portions of code).

[0233] As an example, the executable instructions may be deployed to execute on one computing device, or on multiple computing devices located at one site, or, on multiple computing devices distributed across multiple sites and interconnected by a communication network.

[0234] In summary, through the embodiments of the present application, dynamic replacement of resources is achieved, so that the hot deployment of resources can take effect without restarting the process.

[0235] The above is only the embodiments of the present application and is not intended to limit the protection scope of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are all included in the protection scope of the present application.

Claims

1. A method for updating resources of an application, characterized in that The method includes: During the running of the application, obtaining an update resource package of the application, where the update resource package includes update resources and executable files; Based on the executable file, creating a plug-in class loader corresponding to the update resource package and generating a class loader set including at least one non-plug-in class loader; In the class loader chain corresponding to the application, obtaining a host class loader and replacing the parent class loader of the host class loader with the plug-in class loader to obtain a target class loader chain; Based on at least one of the class loader set and the target class loader chain, determining a target class loader for loading the target class to which the update resource belongs; Loading the target class through the target class loader and running the function corresponding to the target class based on the update resource; Among them, the determining the target class loader for loading the target class to which the update resource belongs based on at least one of the class loader set and the target class loader chain includes: Based on the class loaders corresponding to each node in the target class loader chain, determining the target class loader for loading the target class to which the update resource belongs; When the target class loader cannot be determined based on the target class loader chain, determining the target class loader based on the class loaders in the class loader set, where the class loaders in the target class loader chain have a hierarchical relationship, and the class loaders in the class loader set do not have a hierarchical relationship.

2. The method according to claim 1, characterized in that, The determining the target class loader for loading the target class to which the update resource belongs based on the class loaders corresponding to each node in the target class loader chain includes: Based on the hierarchical relationship between the class loaders in the target class loader chain, determining a sub-hierarchical relationship with the plug-in class loader as the lowest level; Starting from the plug-in class loader, obtaining the class load paths of the class loaders at each level in the sub-hierarchical relationship; Obtaining the target class load path of the target class and comparing the target class load path with each of the class load paths to obtain a comparison result; When the comparison result indicates that the target class load path is different from any of the class load paths, using the plug-in class loader as the target class loader for the target class.

3. The method according to claim 1, characterized in that The determining the target class loader based on the class loaders in the class loader set includes: Obtaining the class load paths of the class loaders in the class loader set; Obtaining the target class load path of the target class and searching for the target class load path in the class load paths of the class loaders to obtain a search result; When the search result indicates that the target class load path exists in the class load paths of the class loaders, using the class loader to which the class load path belongs as the target class loader.

4. The method according to claim 1, characterized in that, The method further includes: Identifying the type of the target class to which the update resource belongs, where the type includes a host class and a plug-in class; Among them, the host class is the class loaded by the host class loader when the application is installed, and the plug-in class is the class loaded by the plug-in class loader when the application is running; Determining a target class loader for loading a target class to which the updated resource belongs based on at least one of the class loader set and the target class loader chain includes: When the type is a host class, determining a target class loader for loading the target class from at least one non-plugin class loader in the class loader set; When the type is a plugin class, obtaining a set of reference class identifiers corresponding to the plugin class loader, and determining a target class loader for loading the target class based on one of the class loader set and the target class loader chain and the set of reference class identifiers; Wherein, the reference class identifier is the class identifier of other classes referenced in the plugin class loader.

5. The method according to claim 4, wherein Determining a target class loader for loading the target class based on one of the class loader set and the target class loader chain and the set of reference class identifiers includes: Matching the class identifier of the target class with each class identifier in the set of reference class identifiers to obtain a matching result; When the matching result indicates that the class identifier of the target class belongs to the set of reference class identifiers, determining a target class loader for loading the target class based on the class loader set; When the matching result indicates that the class identifier of the target class does not belong to the set of reference class identifiers, determining a target class loader for loading the target class based on the target class loader chain.

6. The method according to claim 1, wherein Before running the function corresponding to the target class based on the updated resource, the method further includes: Obtaining the resource loading path of the updated resource and the resource loader of the application; Inserting the resource loading path before the original resource loading path of the application in the resource loader to obtain a target resource loading path; Loading the updated resource into the memory space of the application according to the loading order indicated by the target resource loading path.

7. The method according to claim 6, characterized in that, Loading the target class through the target class loader includes: When it is possible to determine the target class loader of the target class based on at least one of the class loader set and the target class loader chain, obtaining the class loading path of the target class, and controlling the target class loader to perform a loading operation on the target class based on the class loading path; Running the function corresponding to the target class based on the updated resource includes: During the execution of the loading operation, obtaining the updated resource from the memory space of the application based on the resource identifier of the updated resource, and when the loading operation is completed, running the function corresponding to the target class after the resource update based on the updated resource.

8. The method according to claim 1, wherein The method further includes: When it is not possible to determine the target class loader of the target class based on at least one of the class loader set and the target class loader chain, controlling the plugin class loader to capture exception information, and generating an error prompt message based on the exception information; When running the function corresponding to the target class, displaying the error prompt message; Wherein, the error prompt message is used to indicate that the update operation on the application based on the updated resource package fails.

9. The method according to claim 1, characterized in that, During the running of the application, obtaining the update resource package of the application includes: During the running of the application, receiving an update notification sent by the server, where the update notification is used to indicate that there is an update resource package for the application; According to the update notification, downloading the update resource package to the local storage space, and notifying the process of the application, so that the process obtains the update resource package from the local storage space.

10. The method according to claim 1, characterized in that, Based on the executable file, creating a plugin class loader corresponding to the update resource package includes: Parsing the executable file to obtain at least one class to be loaded included in the update resource package; Creating a plugin class loader for loading the at least one class to be loaded; Generating a class loader set including at least one non-plugin class loader includes: Obtaining at least one non-plugin class loader corresponding to the application, and generating a class loader set including at least one non-plugin class loader and other plugin class loaders except the plugin class loader.

11. A resource update device for an application program, characterized in that, The device includes: An obtaining module, configured to obtain the update resource package of the application during the running of the application, where the update resource package includes update resources and an executable file; A generating module, configured to create a plugin class loader corresponding to the update resource package based on the executable file, and generate a class loader set including at least one non-plugin class loader; A replacing module, configured to obtain a host class loader in the class loader chain corresponding to the application, and replace the parent class loader of the host class loader with the plugin class loader to obtain a target class loader chain; A finding module, configured to determine a target class loader for loading the target class to which the update resource belongs based on at least one of the class loader set and the target class loader chain; the finding module is configured to determine the target class loader for loading the target class to which the update resource belongs according to the following method: determining the target class loader for loading the target class to which the update resource belongs based on the class loaders corresponding to the nodes in the target class loader chain; when the target class loader cannot be determined based on the target class loader chain, determining the target class loader based on the class loaders in the class loader set, where the class loaders in the target class loader chain have a hierarchical relationship, and the class loaders in the class loader set do not have a hierarchical relationship; A running module, configured to load the target class through the target class loader, and run the function corresponding to the target class based on the update resource.

12. The device according to claim 11, wherein The searching module is further configured to determine a sub - hierarchical relationship with the plug - in class loader as the lowest level based on the hierarchical relationship among the class loaders in the target class loader chain; starting from the plug - in class loader, obtain the class loading paths of the class loaders at each level in the sub - hierarchical relationship; obtain the target class loading path of the target class, and compare the target class loading path with each of the class loading paths to obtain a comparison result; when the comparison result indicates that the target class loading path is different from any of the class loading paths, use the plug - in class loader as the target class loader of the target class.

13. The apparatus according to claim 11, wherein The searching module is further configured to obtain the class loading paths of the class loaders in the class loader set; obtain the target class loading path of the target class, and search for the target class loading path among the class loading paths of the class loaders to obtain a search result; when the search result indicates that the target class loading path exists among the class loading paths of the class loaders, use the class loader to which the class loading path belongs as the target class loader.

14. The apparatus according to claim 11, wherein The searching module is further configured to identify the type of the target class to which the updated resource belongs, and the type includes a host class and a plug - in class; wherein, the host class is a class loaded by the host class loader when the application is installed, and the plug - in class is a class loaded by the plug - in class loader when the application is running; when the type is the host class, determine the target class loader for loading the target class from at least one non - plug - in class loader in the class loader set; when the type is the plug - in class, obtain the set of reference class identifiers corresponding to the plug - in class loader, and determine the target class loader for loading the target class based on one of the class loader set and the target class loader chain and the set of reference class identifiers; wherein, the reference class identifier is the class identifier of other classes referenced in the plug - in class loader.

15. An electronic device, characterized in that, The electronic device includes: A memory for storing executable instructions; A processor, when executing the executable instructions stored in the memory, implements the resource update method of the application according to any one of claims 1 to 10.

16. A computer-readable storage medium storing executable instructions, characterized in that, The executable instructions, when executed by the processor, implement the resource update method of the application according to any one of claims 1 to 10.

17. A computer program product, comprising a computer program or instructions, characterized in that, The computer program or instructions, when executed by the processor, implement the resource update method of the application according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Android system imperceptible application installation upgrading method

    CN108491216A

  • Application program upgrading method, system and device and computer storage medium

    CN111625256A