A method, device, equipment and medium for real-time repair of online problems of Android applications

By inserting the replacement method entry and building the replacement point logic in the Android application, the problem that the robust solution cannot add parameters is solved, the parameter declaration is changed and security is improved, the impact on performance and package volume is solved, and the hot repair application is enhanced. real-time.

CN118466970BActive Publication Date: 2024-09-17CHENGDU YUBUO TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410932823.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-12
Publication Date
2024-09-17
Estimated Expiration
2044-07-12

AI Technical Summary

Technical Problem

The existing robust solution can only repair the method code, cannot add parameters, and has the risk of poor performance and subsequent API removal. It cannot shield the code generated by the annotation generator from affecting the package volume.

Method used

By inserting the replacement method entry into the method of the class file, build the judgment logic of the replacement point, determine whether to insert a patch file to repair the wrong method, and when executing the repair method, add new parameters through the pre-built instance replacement entry, and shield the annotation generator Generated code to reduce package size.

Benefits of technology

Implemented changes to parameter declarations, increased parameter security, avoided content leakage, solved performance and compatibility issues, and enhanced the real-time nature of hot repair application scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118466970B
    Figure CN118466970B
Patent Text Reader

Abstract

The present invention belongs to the field of hot update technology, and discloses a method, device, equipment and medium for real-time repair of online problems of Android applications, the method comprising: loading a class file, each method of the class file is inserted with a replacement method entry, the replacement method entry is constructed with a judgment logic of a replacement point, and the replacement method entry is used to insert a patch file; when an execution error occurs in any method of the class file, judging whether a patch file is inserted into the replacement method entry based on the judgment logic of the replacement point; if so, replacing the erroneous method with the repair method in the patch file, and executing the repair method; if not, continuing to execute the erroneous method; when executing the repair method, based on a pre-constructed instance replacement entry, performing a modification operation on the parameters of the repair method; wherein the modification operation comprises: adding at least one instance parameter. The present invention can realize the modification of parameter declarations; and adding parameters has high security, which can avoid content leakage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of hot update, and specifically relates to a method, device, equipment and medium for real-time repair of online problems of Android applications. Background Art

[0002] The hot update solution is a technology that fixes application problems without uninstalling the application. It allows developers to remotely push updates to fix bugs, optimize performance, or add new features after the application is released. Users can receive the latest version without having to manually update the application.

[0003] There are some excellent hot update solutions on the Android platform, which can be divided into two categories: one is the hot update framework based on multidex, and the other is the native hook solution, so that the client can also repair online problems in real time.

[0004] The solution based on native hook needs to be adapted to the dalvik virtual machine and the art virtual machine, needs to consider the compatibility of the instruction set, and needs native code support, which will have a certain impact on compatibility. The solution based on Multidex needs to reflectively change DexElements and change the loading order of Dex, which means that the patch will only take effect at the next startup, and the real-time performance is affected.

[0005] In order to solve the above problems, a robust solution has been developed in the prior art. The robust solution is an Android hot update solution developed by the Meituan platform. The robust plug-in automatically inserts a piece of code into each function of each product code during the compilation and packaging stage. The insertion process is completely transparent to business development, and the robust solution has high compatibility.

[0006] However, the robust solution still has at least the following problems in practical applications:

[0007] 1. You can only repair the method code, but cannot add new parameters;

[0008] 2. The code generated by the annotation generator cannot be blocked, which has a certain impact on the package size;

[0009] 3. Reflection calls non-public methods, which have poor performance and the risk of the launch API being removed and unusable in the future. Summary of the invention

[0010] The purpose of the present invention is to provide a method, device, equipment and medium for real-time repair of online problems of Android applications, so as to solve the problem that the existing robust solution can only repair method codes but cannot add new parameters.

[0011] In order to achieve the above object, the present invention adopts the following technical solutions:

[0012] In a first aspect, the present invention provides a method for real-time repair of online problems of an Android application, the method comprising:

[0013] Loading a class file, wherein each method of the class file is inserted with a replacement method entry, wherein the replacement method entry is constructed with a judgment logic of a replacement point, and the replacement method entry is used to insert a patch file;

[0014] When an execution error occurs in any method of a class file, the judgment logic of the replacement point determines whether a patch file is inserted into the replacement method entry; if so, the error method is replaced with the repair method in the patch file and the repair method is executed; if not, the error method continues to be executed;

[0015] When executing the repair method, based on the pre-built instance replacement entry, a modification operation is performed on the parameters of the repair method; wherein the modification operation includes: adding at least one instance parameter.

[0016] Preferably, the method further comprises:

[0017] When an execution error occurs in any method of a class file, a patch file corresponding to the erroneous method is created;

[0018] Issue the patch file and insert the patch file into the replacement method entry.

[0019] Preferably, the method further comprises:

[0020] In all project submodules, find the project submodules that have dependency annotation plugins;

[0021] Record the directory of code automatically generated by annotation plug-ins;

[0022] When executing the repair method, the directory where the code is automatically generated by the annotation plugin is accessed to obtain the class of the code.

[0023] Preferably, among all project submodules, search for project submodules that have dependency annotation plugins, including:

[0024] Get all project submodules;

[0025] Traverse the project submodules and obtain the configuration files of the project submodules;

[0026] Check whether the configuration file contains the annotation plug-in. If so, get the project submodule that depends on the annotation plug-in.

[0027] Preferably, the declaration period of the instance replacement entry is consistent with the declaration period of the host class corresponding to the instance replacement entry.

[0028] Preferably, the host class contains at least one non-public method, and the method further includes:

[0029] Access at least one non-public method of the host class based on a pre-built access plan.

[0030] Preferably, constructing an access plan includes:

[0031] Read all methods of each class file and filter out the host classes corresponding to all non-public methods;

[0032] Create an offset parameter for each host class;

[0033] After the instrumentation is completed, a mapping table of offsets and methods corresponding to each class file is generated;

[0034] According to the mapping table and patch file of the offset and method corresponding to each class file, an access scheme is constructed, wherein the access scheme is used to automatically convert the call of the non-public method into the offset access of the non-public method.

[0035] In a second aspect, the present invention provides a device for repairing online problems of an Android application in real time, the device being used to implement the above-mentioned method for repairing online problems of an Android application in real time, the device comprising:

[0036] A loading module, used for loading a class file, wherein each method of the class file is inserted with a replacement method entry, wherein the replacement method entry is constructed with a judgment logic of a replacement point, and the replacement method entry is used for inserting a patch file;

[0037] The repair module is used to determine whether to insert a patch file into the replacement method entry when an execution error occurs in any method of the class file based on the judgment logic of the replacement point; if so, replace the erroneous method with the repair method in the patch file and execute the repair method; if not, continue to execute the erroneous method;

[0038] The modification module is used to perform modification operations on the parameters of the repair method based on the pre-built instance replacement entry when executing the repair method; wherein the modification operation includes: adding at least one instance parameter.

[0039] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for real-time repair of online problems of Android applications when executing the computer program.

[0040] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-mentioned method for real-time repair of online problems of Android applications.

[0041] Beneficial effects:

[0042] The present invention uses a pre-built instance replacement entry. When executing a repair method, method parameters can be added according to the instance replacement entry to achieve changes in parameter declarations; and adding parameters has high security and can avoid content leakage. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present invention, but do not constitute a limitation on the embodiments of the present invention. In the accompanying drawings:

[0044] Figure 1 It is a flow chart of a method for real-time repair of online problems of Android applications provided by one embodiment of the present invention;

[0045] Figure 2 It is a block diagram of a device for real-time repair of online problems of Android applications provided by one embodiment of the present invention. DETAILED DESCRIPTION

[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.

[0047] Embodiment 1

[0048] The reference scenarios of the real-time repair method for online problems of Android applications in this embodiment include: an Android terminal and a cloud server, the Android terminal is communicated with the cloud server, an APP (APPlication, APP) application software is running on the Android terminal, and the cloud service is used to monitor the running status of the APP application software on the Android terminal. When an operation error occurs in the Android terminal, a corresponding patch file is created, and the patch file is used to repair the operation error.

[0049] Based on the above cited scenario, this embodiment provides a method for real-time repair of online problems of Android applications. Figure 1 is a flow chart of a method for real-time repair of online problems of Android applications provided by an embodiment of the present invention, such as Figure 1 As shown, the method includes:

[0050] Step S10: loading a class file, wherein each method of the class file is inserted with a replacement method entry, wherein the replacement method entry is constructed with a judgment logic of a replacement point, and the replacement method entry is used to insert a patch file.

[0051] In this embodiment, the judgment logic of the replacement point is executed locally on the Android terminal, and the judgment logic of the replacement point is: when the class file runs normally, the replacement point is empty, and the original method logic of the class file is executed at this time; when the class file is running, when there is a problem with an online method (such as a bug), it is necessary to determine whether the replacement point is empty. When it is empty, it indicates that there is no patch file for repairing the method at the replacement point. When it is not empty, it indicates that there is a patch file for repairing the method at the replacement point.

[0052] Step S20: When an execution error occurs in any method of the class file, determine whether a patch file is inserted into the replacement method entry based on the judgment logic of the replacement point; if so, replace the erroneous method with the repair method in the patch file and execute the repair method; if not, continue to execute the erroneous method.

[0053] As a further optimization of this embodiment, the method further includes:

[0054] Step S201: When an execution error occurs in any method of a class file, the cloud server generates a patch file corresponding to the erroneous method;

[0055] Step S202: the cloud server sends a patch file, and after the Android terminal receives the patch file, it inserts the patch file into the replacement method entry.

[0056] In this embodiment, an execution error in any method of a class file can be analyzed by the cloud server, or it can be feedback from users regarding problems that occur during the operation of the APP software. The cloud server analyzes the method where the error occurs based on the feedback; the cloud server creates a corresponding patch file based on the erroneous method, and then sends the patch file to the Android terminal; the Android terminal inserts the received patch file into the replacement method entry.

[0057] In this embodiment, when the cloud server has not made the corresponding patch file, the replacement point is empty. When the APP application software runs to the method of the class file with an error, since the replacement point is empty, it will continue to execute the original erroneous method to ensure the operation of the program; and when the cloud server has made the patch file, the replacement point is not empty; when the APP application software runs to the method of the class file with an error, it will skip the original execution logic (that is, the erroneous method) and use the repair method in the patch file instead, and continue to run the program with the repair method, so as to achieve the purpose of real-time repair of online problems.

[0058] Step S30: When executing the repair method, based on the pre-built instance replacement entry, a modification operation is performed on the parameters of the repair method; wherein the modification operation includes: adding at least one instance parameter.

[0059] In this embodiment, hot repair of application runtime errors is achieved by reserving replacement method entries, and the parameter declarations of all methods of the class file cannot be changed. However, in actual bug repair scenarios, it is often necessary to add new method parameters, that is, to modify and adjust the parameters of some methods of the class file.

[0060] In order to modify the parameter declaration of the method of the class file, in this embodiment, an instance replacement entry is added on the basis of replacing the method entry. The declaration period of the class of the instance replacement entry is consistent with the declaration period of the host class corresponding to the instance replacement entry. At this time, the parameters of the repair method can be modified through the instance replacement entry.

[0061] Therefore, the present invention uses a pre-built instance replacement entry. When executing the repair method, method parameters can be added according to the instance replacement entry to achieve changes in parameter declarations; and adding parameters has high security and can avoid content leakage.

[0062] As a further optimization of this embodiment, the method further includes:

[0063] Step a01: Search for project submodules that have dependency annotation plugins in all project submodules;

[0064] Step a02: Record the directory of the code automatically generated by the annotation plug-in;

[0065] Step a03: When executing the repair method, access the directory of the code automatically generated by the annotation plug-in to obtain the class of the code.

[0066] In this embodiment, the solution of automatically generating code by using gradle's annotations is widely used in Android development; gradle is a popular open source build tool used in the build process of Android projects. In gradle, code generation by annotations is a common practice, which can automatically generate code during compilation through annotation processors. This method can simplify the writing of template code, improve development efficiency, and reduce duplicate code.

[0067] Insert a replacement method entry into each method of the class file. When using gradle to automatically generate code, invalid hooks can also be inserted, which will increase the size of the application package. In order to reduce the size of the application package, use steps a01 to a02 to find all project submodules that have dependent annotation plug-ins, and record the directory of automatically generated code. When hot-fixing the plug-in at the end, access the directory to get all the classes of generated code, do not plug in the plug-in, and automatically shield the generated code plug-in to achieve the effect of reducing the size of the application package.

[0068] In this embodiment, for step a01, specifically, searching for a project submodule that has a dependency annotation plug-in in all project submodules includes:

[0069] Step a0101: Get all project submodules;

[0070] Step a0102: traverse the project submodules and obtain the configuration files of the project submodules;

[0071] Step a0103: Check whether the configuration file contains the annotation plug-in. If so, obtain the project submodule that depends on the annotation plug-in.

[0072] In this embodiment, all project submodules that depend on the annotation plug-in can be found through steps a0101 to a0103.

[0073] In this embodiment, when the wrong method is hot-repaired online using steps S10 and S20, the method actually executed by the hot-repair is on an external class, and the host class contains at least one non-public method, so the non-public method of the host class cannot be accessed during the hot-repair. In the prior art, reflection is used to solve this problem, and the following method is used:

[0074] After the Android terminal obtains the patch.dex containing PatchesInfoImpl.java and StatePatch.java, it uses DexClassLoader to load patch.dex and obtain the PatchesInfoImpl.java class through reflection. After obtaining it, an object of this class is created. Then, through the getPatchedClassesInfo function of this object, it is known that the class to be patched is com. yupao.sample.d (the obfuscated name of com. yupao.sample.State). Then, the com. yupao.sample.d class in the current running environment is obtained through reflection, and the changeQuickRedirect field is assigned to the object newly created by the StatePatch.java class in patch.dex.

[0075] However, the above method has two defects in practical application: first, it is time-consuming; second, Android officially no longer recommends reflection.

[0076] In order to solve the technical problem that the non-public method of the host class cannot be accessed during repair, the host class includes at least one non-public method, and the method further includes: accessing at least one non-public method of the host class based on a pre-built access plan.

[0077] Specifically, construct an access plan, including:

[0078] Step b01: Read all methods of each class file and filter out the host classes corresponding to all non-public methods;

[0079] Step b02: Create an offset parameter for each host class respectively;

[0080] Step b03: after the stub is inserted, a mapping table of offsets and methods corresponding to each class file is generated;

[0081] Step b04: construct an access plan based on the mapping table and patch file of the offset and method corresponding to each class file, wherein the access plan is used to automatically convert the call of the non-public method into the offset access of the non-public method.

[0082] In this embodiment, by reading the methods of each class, an access method with an offset parameter is added to the class containing the non-public method (i.e., the host class), and the non-public method is accessed through the offset, and a mapping table of the corresponding offset and method of each class is generated after the instrumentation is completed. In conjunction with the patch plug-in, the non-public method call is automatically converted to offset access. For example: for example, the first non-public method noPublic of class A, then the offset of this non-public method is 01. After the instrumentation plug-in is finished, there will be such a mapping table file, and the patch plug-in can convert the access to the non-public method into the access to the public method to be offset left before according to this mapping file.

[0083] The present invention has the following advantages:

[0084] 1. Solved the problem that the method could not add new parameters, and added hot repair application scenarios;

[0085] 2. Shield the plug-in of automatically generated code, greatly reducing the package size;

[0086] 3. Solved the risks and performance issues of reflection calls.

[0087] Embodiment 2

[0088] Figure 2 is a block diagram of a device for real-time repair of online problems of Android applications provided by an embodiment of the present invention, such as Figure 2 As shown, this embodiment provides a device for real-time repair of online problems of Android applications, and the device is used to implement the method for real-time repair of online problems of Android applications of embodiment 1, and the device includes:

[0089] A loading module, used for loading a class file, wherein each method of the class file is inserted with a replacement method entry, wherein the replacement method entry is constructed with a judgment logic of a replacement point, and the replacement method entry is used for inserting a patch file;

[0090] The repair module is used to determine whether to insert a patch file into the replacement method entry when an execution error occurs in any method of the class file based on the judgment logic of the replacement point; if so, replace the erroneous method with the repair method in the patch file and execute the repair method; if not, continue to execute the erroneous method;

[0091] The modification module is used to perform modification operations on the parameters of the repair method based on the pre-built instance replacement entry when executing the repair method; wherein the modification operation includes: adding at least one instance parameter.

[0092] This embodiment also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method for real-time repair of online problems of Android applications of the first embodiment when executing the computer program.

[0093] This embodiment also provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the real-time repair method for online problems of Android applications in embodiment one is implemented.

[0094] The present invention uses a pre-built instance replacement entry. When executing a repair method, method parameters can be added according to the instance replacement entry to achieve changes in parameter declarations; and adding parameters has high security and can avoid content leakage.

[0095] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program codes.

[0096] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0097] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A real-time repair method for online problems of Android applications, characterized in that: The method comprises: A class file is loaded, each method of the class file is inserted with a replacement method entry, a judgment logic of a replacement point is constructed in the replacement method entry, and the replacement method entry is used to insert a patch file; wherein the judgment logic is that when the class file is running normally, the replacement point is empty, and the original method logic of the class file is executed; when the class file is running, if there is a problem with any online method, it is judged whether the replacement point is empty, and when it is empty, it indicates that there is no patch file for repairing the method at the replacement point, and when it is not empty, it indicates that there is a patch file for repairing the method at the replacement point; When an execution error occurs in any method of a class file, the judgment logic of the replacement point determines whether a patch file is inserted into the replacement method entry; if so, the error method is replaced with the repair method in the patch file and the repair method is executed; if not, the error method continues to be executed; When executing the repair method, based on the pre-built instance replacement entry, a modification operation is performed on the parameters of the repair method; wherein the modification operation includes: adding at least one instance parameter.

2. The method for real-time repair of online problems of Android applications according to claim 1, characterized in that: The method further comprises: When an execution error occurs in any method of a class file, a patch file corresponding to the erroneous method is created; Issue the patch file and insert the patch file into the replacement method entry.

3. The method for real-time repair of online problems of Android applications according to claim 1, characterized in that: The method further comprises: In all project submodules, find the project submodules that have dependency annotation plugins; Record the directory of code automatically generated by annotation plug-ins; When executing the repair method, the directory where the code is automatically generated by the annotation plugin is accessed to obtain the class of the code.

4. The method for real-time repair of online problems of Android applications according to claim 3 is characterized in that: In all project submodules, search for project submodules that have dependency annotation plugins, including: Get all project submodules; Traverse the project submodules and obtain the configuration files of the project submodules; Check whether the configuration file contains the annotation plug-in. If so, get the project submodule that depends on the annotation plug-in.

5. The method for real-time repair of online problems of Android applications according to claim 1, characterized in that: The declaration period of the instance replacement entry is consistent with the declaration period of the host class corresponding to the instance replacement entry.

6. The method for real-time repair of online problems of Android applications according to claim 5, characterized in that: The host class includes at least one non-public method, and the method further includes: Access at least one non-public method of the host class based on a pre-built access plan.

7. The method for real-time repair of online problems of Android applications according to claim 5, characterized in that: Build an access plan, including: Read all methods of each class file and filter out the host classes corresponding to all non-public methods; Create an offset parameter for each host class; After the instrumentation is completed, a mapping table of offsets and methods corresponding to each class file is generated; According to the mapping table and patch file of the offset and method corresponding to each class file, an access scheme is constructed, wherein the access scheme is used to automatically convert the call of the non-public method into the offset access of the non-public method.

8. A device for repairing online problems of Android applications in real time, the device being used to implement the method for repairing online problems of Android applications in real time according to any one of claims 1 to 7, characterized in that: The device comprises: A loading module, used for loading a class file, wherein each method of the class file is inserted with a replacement method entry, wherein the replacement method entry is constructed with a judgment logic of a replacement point, and the replacement method entry is used for inserting a patch file; The repair module is used to determine whether to insert a patch file into the replacement method entry when an execution error occurs in any method of the class file based on the judgment logic of the replacement point; if so, replace the erroneous method with the repair method in the patch file and execute the repair method; if not, continue to execute the erroneous method; The modification module is used to perform modification operations on the parameters of the repair method based on the pre-built instance replacement entry when executing the repair method; wherein the modification operation includes: adding at least one instance parameter.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the real-time repair method for online problems of Android applications described in any one of claims 1-7 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the real-time repair method for online problems of Android applications described in any one of claims 1-7 is implemented.