Method for modifying third-party library, plug-in, electronic equipment and storage medium
By copying and modifying third-party library classes in the user library and replacing them at compile time using Gradle Transform API, the problem of large workload, difficulty in maintaining and long compilation time in the existing technology is solved, and the modification is achieved. Continuity and compatibility.
Patent Information
- Application Number
- CN202310531680.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-11
- Publication Date
- 2024-11-12
AI Technical Summary
In the prior art, the method of modifying third-party libraries is very laborious, difficult to maintain, and long compilation time, and it is difficult to maintain the continuity of modifications. In particular, a lot of work is required to confirm the suitability of modifications when upgrading third-party libraries.
By creating an independent user library, copying and modifying classes in third-party libraries, establishing mapping relationships between classes, and using the Gradle Transform API to replace the modified class with the original class to keep the class names consistent, and using Gradle Transform The mechanism implements class replacement during compilation.
Simplifies the modification process of third-party libraries, reduces workload, reduces compilation time, and maintains the continuity of modifications when upgrading third-party libraries, avoiding compatibility issues.
Smart Images

Figure CN118939312A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method for modifying a third-party library, a plug-in, an electronic device, and a storage medium. Background Art
[0002] Smart mobile devices have evolved through several generations of technology. Currently, the mainstream operating system for smart mobile devices is Android. Since Android is an open source system, there are a lot of library resources. When developing applications, program developers can call on a variety of existing libraries (i.e., third-party libraries) to meet their own needs.
[0003] However, calling library files written and maintained by others may have some unsatisfactory features and cannot fully meet the current needs of program developers. Therefore, program developers are required to adaptively modify the called library files to meet their own usage needs.
[0004] Currently, the most common method to modify a third-party library is to clone the entire project code of the third-party library, and then modify the source code of the third-party library for your own use. However, this modification method has the following defects:
[0005] A) The workload for programmers is huge, which is equivalent to rebuilding a library, and compilation problems may also occur.
[0006] B) Difficulty in later maintenance. When the third-party library is upgraded, the above adaptive modifications need to be manually ported to the new version of the third-party library by the program developers. However, since the modifications of the third-party library are unknown, the program developers cannot blindly copy the modifications in the old version to the new version, but need a lot of work to confirm whether the modification is appropriate.
[0007] C) Increased compilation time; each modification requires recompilation and release of a new version.
[0008] Therefore, there is an urgent need to develop a new method for modifying third-party libraries so that the third-party libraries can be modified more simply and not be affected by the upgrade of the third-party libraries, thereby maintaining the continuity of the modified part. Summary of the invention
[0009] In order to solve the above defects and improve the convenience of modifying a third-party library, the present invention proposes a method for modifying a third-party library, a plug-in, an electronic device, and a storage medium.
[0010] The present invention first proposes a method for modifying a third-party library, comprising:
[0011] Create an independent first library to store the modified classes;
[0012] Copy the first class to be modified from the third-party library to the first library;
[0013] modifying the first class in the first library to obtain a second class;
[0014] Establishing a mapping relationship between the second class and the first class in the third-party library;
[0015] During compilation, a first Transform API is inserted into the TransformTask chain, and the first Transform API replaces the first class with the second class when copying the third-party library.
[0016] In the above method, the file names of the first category and the second category remain consistent.
[0017] In the above method, modifying the first category in the first library to obtain the second category further includes: publishing the second category as an aar file.
[0018] In the above method, replacing the first category with the second category includes:
[0019] Traversing each library, obtaining all classes in one or more of the first libraries to form a modified class group;
[0020] Each library is traversed again, and specific classes copied from the third-party library are refused according to the mapping relationship, where the specific classes refer to unmodified classes corresponding to the classes in the modified class group.
[0021] In the above method, the step of modifying the first category in the first library to obtain the second category comprises:
[0022] Keep the method names and variable names in the first class unchanged;
[0023] Modify the method's logic;
[0024] Modify the properties of methods and variables;
[0025] Add new classes, methods, and variables.
[0026] Based on the same inventive concept, the present invention also provides a plug-in for modifying a third-party library, including:
[0027] An editing module, used for creating an independent first library, then copying the first class to be modified from the third-party library to the first library, and modifying the first class in the first library to obtain the second class;
[0028] The compile module replaces the first category with the second category when copying the third-party library according to the mapping relationship between the first category and the second category.
[0029] In the above plug-in, the compilation module includes a first Transform API. When replacing the first class with the second class, the first Transform API traverses each library twice:
[0030] During the first traversal, all classes in one or more of the first libraries are obtained to form a modified class group;
[0031] During the second traversal, specific classes are refused to be copied from the third-party library according to the mapping relationship, where the specific classes refer to unmodified classes corresponding to the classes in the modified class group.
[0032] Based on the same inventive concept, the present invention also provides an electronic device, including:
[0033] at least one memory for storing computer instructions;
[0034] At least one processor implements the above method when the at least one processor executes the computer instructions.
[0035] Based on the same inventive concept, the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores at least one computer instruction, and the at least one instruction is loaded and executed by a processor to implement the above method.
[0036] Based on the same inventive concept, the present invention also provides a computer program product, which includes a computer program / instructions. When the computer program / instructions are executed by a processor, the above method is implemented.
[0037] Compared with the prior art, the present application saves the modified classes in the third-party library in a centralized manner in the newly created user library, and then uses the Transform mechanism in the Gradle tool to insert an API in the Transform responsibility chain to achieve the effect of replacing the corresponding classes in the third-party library with the modified classes. In addition, the modified classes saved in the user library keep the same name as the corresponding classes in the third-party library, so compatibility issues are not likely to occur when using and upgrading the third-party library. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A block diagram showing how a compilation tool packages and generates an executable file when a third-party library is directly called;
[0039] Figure 2 A block diagram showing a compilation tool packaging and generating an executable file when modifications are made and a third-party library is called according to some embodiments of the present application;
[0040] Figure 3A flowchart of a method for modifying a third-party library proposed according to some embodiments of the present application is shown;
[0041] Figure 4 A schematic diagram showing class replacement proposed according to some embodiments of the present application is shown;
[0042] Figure 5 A block diagram of a plug-in for modifying a third-party library according to some embodiments of the present invention is shown;
[0043] Figure 6 A schematic diagram of the basic hardware structure of an electronic device proposed according to some embodiments of the present application is shown. DETAILED DESCRIPTION
[0044] The following specific embodiments illustrate the implementation of the present invention, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. Although the description of the present invention will be introduced in conjunction with the preferred embodiment, this does not mean that the features of this invention are limited to this implementation. On the contrary, the purpose of introducing the invention in conjunction with the implementation is to cover other options or modifications that may extend based on the claims of the present invention. In order to provide a deep understanding of the present invention, the following description will include many specific details. The present invention can also be implemented without using these details. In addition, in order to avoid confusion or blurring the focus of the present invention, some specific details will be omitted in the description. It should be noted that the embodiments of the present invention and the features in the embodiments can be combined with each other without conflict.
[0045] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0046] Figure 1The block diagram of the compilation tool packaging and generating an executable file when directly calling a third-party library is shown, that is, a diagram showing the relationship between source code and machine code. As is well known, the program running in the electronic device is a binary code that is easy for the machine to recognize, that is, the machine code 13, and the program developers use a human-readable programming language, that is, the source code 11, when developing the application. The two need to be converted through a compilation tool 12, and the compilation tool 12 "translates" the source code 11 that the electronic device cannot recognize into a machine code 13 that the electronic device can recognize and execute. Since the source code 11 usually calls the existing program library, that is, the third-party library 14, when the compilation tool 12 "translates" the source code 11, it is usually necessary to copy and compile the contents of the third-party library 14. Otherwise, the finally generated machine code 13 may not work properly. However, the third-party library 14 is developed and maintained by a third-party team. A simple user (such as the user's own R&D team) cannot know what content in the library has been modified by the third-party team. Therefore, when the third-party library 14 is upgraded, it is necessary to use the compilation tool 12 to recompile the source code 11 (including the third-party library 14) accordingly to generate a machine code 13 that matches the new version of the third-party library 14.
[0047] Figure 2 A block diagram of a compilation tool packaging and generating an executable file when modifying and calling a third-party library according to some embodiments of the present application is shown. When a user needs to make adaptive modifications based on a third-party library 14 to meet his own needs, the third-party library 14 is first copied to a local or other data warehouse in the programming stage, and then the third-party library is modified in the local / data warehouse. Preferably, only one or more classes (LibClass) that need to be modified in the third-party library 14 (Lib) can be copied. Further, multiple classes in multiple third-party libraries 14 can also be copied. The copied classes can be centrally stored in a newly created user library, and these classes can be modified in the user library. This user library can be an independent, dedicated to storing the classes in the modified third-party library, that is, the user library is a third-party library 141 modified by the user. Then, when the compilation tool 12 is used to compile the source code 11, the corresponding classes in the third-party library 14 are replaced with the modified classes in the user library in the stage of copying the dependent package to keep the library used by the application developed by the user library upgraded synchronously with the third-party library.
[0048] The following, combined Figure 3 Specifically explains how to implement the process of replacing a modified class in a user library with a corresponding class in a third-party library. Figure 3 A flowchart of a method for modifying a third-party library proposed according to some embodiments of the present application is shown.
[0049] S31, create an independent first library to save the modified classes. Unlike third-party libraries, this is a user library used to save classes modified by users. For example, suppose we want to modify the source code of the image loading library Fresco, then we can create a library named xyFresco locally (or in the cloud, just make sure the path is clear). This xyFresco library can be used as a special library to save classes that will be modified later. It can be understood that if you need to modify classes in other third-party libraries, you can create a new library to save the modifications, or you can save them directly in xyFresco, and then accurately record the mapping relationship between the user library and the classes in the third-party library.
[0050] S32, copy the first class to be modified from the third-party library to the first library. Preferably, the name of the first class can be kept unchanged, that is, the class copied from the third-party library to the first library can keep the name of the original class unchanged. Since the library is a supporting file, even if the third-party library is modified to become a user library, it can still be called by other programs on the user side. In order to ensure the validity of all software calls to it, the name of the class can be kept unchanged, but the class is identified through different paths. For example, the class under the Fresco directory is the first class maintained by the third party, and the class under the xyFresco directory is the second class modified (or maintained) by the user.
[0051] In this step, only one or several classes in the library file are copied. Compared with copying the entire library file in the prior art, this not only reduces the time for downloading and copying (because the library files are often very large), but also avoids a large amount of procedural work encountered when modifying the entire library file.
[0052] S33, modify the first class in the first library to obtain the second class. When modifying, modify some parameters, logic, etc. in the class according to your own needs. It is not recommended to modify the names of various methods, variables, etc. in the class. In other words, the difference between the first class and the second class lies in the specific content of the package, while the names that may be used when calling (variable names, method names, etc.) remain the same. For example, the logic of the methods in the class can be modified (or even completely changed); the properties of the methods and variables in the class, such as visibility, can also be modified; methods and variables that are not in the first class can also be added to the second class; or classes that are not in the third-party library can also be added to the first library.
[0053] After the modification is completed, the first library can be published as an aar (Android Archive, a binary archive file of an Android library project) file.
[0054] S34, establish a mapping relationship between the second class and the first class in the third-party library. As disclosed in S31, there is a corresponding relationship between the second class obtained by modifying the first class and the corresponding first class, and this relationship will be used when the apk package is subsequently made (i.e. packaged as an executable program). In this step, the mapping relationship between the two can be specified in the configuration item of the compilation tool. Specifically, according to the content of the present invention, an API (Application Programming Interface) for implementing a method for modifying a third-party library can be generated. For example, the API can be named LibcodeEditor. The LibcodeEditor is connected to the commonly used project building tool (i.e., compilation tool) Gradle, and the mapping relationship between the first class and the second class can be saved in the configuration of LibcodeEditor. When Gradle builds the apk package, for the modified third-party library, the mapping relationship in the configuration of LibcodeEditor can be used to decide whether to package the class in the first library or the class in the third-party library into the apk package.
[0055] S35, during compilation, the first Transform API is inserted into the TransformTask chain, and the first Transform API replaces the first category with the second category when copying the third-party library.
[0056] Take Gradle as an example. It is a project building tool provided by Android to developers, and is reflected in the project directory of Android Studio. Gradle can convert Java source files, resource files, dependency packages, common configuration files, etc. in Android projects into one or more apk files through a series of steps. Only with apk files can they be released to the application market. Starting from Gradle 1.5, the tool provides a set of Gradle Transform APIs, which can modify class files during the project construction phase (i.e., during the conversion from class to dex). Among them, each Transform is a Gradle Task, which connects multiple Transforms with different functions in series to form a TransformTask responsibility chain. Usually, the first Transform receives the results of the javac compilation, as well as the third-party dependencies (such as library files in aar format) and resource resources pulled to the local. These compiled intermediate products flow on the Transform chain. Each Transform can process the class and then pass it to the next Transform for another processing. The processing results are transmitted between adjacent Transforms through paths, that is, the outputDir of the previous Transform is the inputDir of the next Transform.
[0057] The first Transform API customized by the user side can be inserted into the TransformTask responsibility chain to implement the operation of replacing the first category with the second category. Specifically, the first Transform API performs the following steps:
[0058] Traverse each library, obtain all classes in one or more of the first libraries, and form a modified class group. When a project involves modifying multiple third-party libraries, it is necessary to set up a first library for each third-party library, and the package name and class name in the first library are the same as the package name and class name in the corresponding third-party library. When traversing each library for the first time, copy all (may be one, may be multiple) first libraries and the package names and class names in the library and record them in the modified class group.
[0059] Each library is traversed again, and specific classes copied from the third-party library are refused according to the mapping relationship, where the specific classes refer to unmodified classes corresponding to the classes in the modified class group.
[0060] Can also be combined Figure 4 To understand the specific replacement process. Figure 4A schematic diagram of class replacement provided according to some embodiments of the present application is shown. The third-party library 14 includes 3 library files Lib1 to Lib3, wherein each library has a class, such as class 41 (Lib1Class2), class 42 (Lib2Class3), and class 43 (Lib3Class4), which need to be modified, and the modified class exists in the third-party library 141 modified by the self. In the figure, in order to distinguish between unmodified classes and modified classes, classes 41 to 43 are displayed as classes 41a (ModifiedLib1Class2), class 42a (ModifiedLib2Class3), and class 43a (ModifiedLib3Class4) in the third-party library 141 modified by the self. In actual operation, the names of the corresponding classes in the third-party library 14 and the third-party library 141 modified by the self should be kept consistent as described in step S32.
[0061] When the first Transform API traverses each library for the first time, it obtains all classes in the third-party library 141 modified by itself, such as classes 41a to 43a, which form a class group. In addition, the class group can be stored in the outputDir that transfers the processing results between Transforms, so that when the subsequent Transform obtains the class, it can obtain it from the specified directory according to the instruction of outputDir.
[0062] The first Transform API finds classes 41-43 corresponding to classes 41a-43a from the third-party library 14 based on the class group and the mapping relationship established in step S34 when traversing the libraries for the second time. When copying the third-party library 14, only the unmodified classes, such as Figure 4 Lib1Class1 in is copied directly to outputDir, and the modified class, such as Figure 4 Lib1Class2 (class 41) in has been copied to outputDir during the previous traversal of the libraries, so the third-party library under outputDir (i.e., the third-party library 142 packaged in the apk) is the library that contains the modified class.
[0063] After the above processing, the effect of using classes 41a-43a to replace classes 41-43 is achieved. The library file actually packaged in the apk file is the third-party library 142 packaged in the apk including classes 41a-43a.
[0064] Then, combined with the concurrent compilation and incremental compilation techniques in Gradle, you can compile quickly (usually completed within 3 seconds), so that when encountering third-party library upgrades, you can quickly recompile and reduce the intensity of releasing a new version of the apk.
[0065] However, for the Gradle tool, since there is an app:checkDebugDuplicateClasses task in the process of packaging the apk, this task is used to check whether there are duplicate classes in all the aars that the app depends on, and according to the Transform mechanism of Gradle, this task is executed before all TransformTasks. Then at this time, the app:checkDebugDuplicateClasses task will definitely issue a duplicate name warning because there are classes with the same package name and class name in the third-party library 142 and the third-party library 141 modified by the party. Therefore, it is necessary to disable the app:checkDebugDuplicateClasses task in advance. Disabling this task will not cause substantial defects. Because, in the inherent packaging process of the Gradle tool, the dexBuilder task is also included later, and this task will also check whether there are duplicate classes in the entire apk. As long as the aforementioned first Transform API is executed before the dexBuilder task, the dexBuilder task can discover the duplicate name defect.
[0066] Figure 5 A block diagram of a plug-in for modifying a third-party library according to some embodiments of the present invention is shown. The plug-in includes an editing module 51 and a compiling module 52 .
[0067] The editing module 51 is used to create an independent first library, then copy the first class to be modified from the third-party library to the first library, and modify the first class in the first library to obtain the second class. For detailed instructions on editing the second class, please refer to the relevant Figure 3 Description.
[0068] The compiling module 52 replaces the first category with the second category when copying the third-party library according to the mapping relationship between the first category and the second category.
[0069] Specifically, the compilation module 52 may include a first Transform API. When replacing the first class with the second class, the first Transform API traverses each library twice: in the first traversal, all classes in the first library are obtained to form a modified class group; in the second traversal, specific classes are refused to be copied from the third-party library according to the mapping relationship. The specific classes refer to the unmodified classes corresponding to the classes in the modified class group. For a more detailed description of the compilation module 52, please refer to the relevant Figure 3 Description.
[0070] The embodiment of the method for modifying a third-party library provided by the present invention can be executed in various electronic devices such as servers. Figure 6A basic hardware structure diagram of an electronic device 100 according to some embodiments of the present application is provided.
[0071] like Figure 6 As shown, the electronic device 100 at least includes a main processor 101 and a storage medium 103. According to different actual use requirements, the electronic device 100 may also include a coprocessor 102, an I / O unit 104, a network communication unit 105, and some other expansion units 106. The selectivity of the coprocessor 102, the I / O unit 104, the network communication unit 105, and other expansion units 106 is shown in the figure by dotted lines.
[0072] The main processor 101 and / or the coprocessor 102 are used to execute computer instructions stored in the storage medium 103 to implement the method proposed in the present invention. The main processor 101 is the control center of the electronic device 100, which is usually a general-purpose processor (for example, Intel's CPU series), which can achieve logical processing and arithmetic calculations in a relatively balanced manner. The main processor 101 uses various interfaces to connect various parts of the entire electronic device 100, and realizes various functions of the electronic device 100 by running or executing software programs stored in the storage medium 103, and calling data stored in the storage medium 103, thereby monitoring the electronic device 100 as a whole.
[0073] The coprocessor 102 is usually a dedicated processor (e.g., a user-programmable embedded microprocessor) used to implement a single function. For example, the coprocessor 102 may be a graphics processor (GPU) dedicated to processing graphics and images. The main processor 101 does not directly process information about graphics and images at this time, but provides data from other units to the coprocessor 102 or sends management instructions to the coprocessor 102 to instruct the coprocessor 102 to obtain data from other units, and after the coprocessor 102 processes the data, the main processor 101 receives the processing result from the coprocessor 102 so that other decisions can be made based on the processing result. For different professional fields, the coprocessor 102 can also be a signal processor, a network communication processor, a complex computing processor, etc. Usually, the hardware implementation basis of the coprocessor 102 is a digital signal processing (DSP) chip, or a complex programmable logic device (CPLD), a field programmable gate array (FPGA), and other application-specific integrated circuits (ASIC, Application Specific Integrated Circuit).
[0074] The storage medium 103 may include an internal memory and an external memory, or may also include a volatile memory and a non-volatile memory, or may also include a magnetic storage device, a solid-state memory, a flash memory, a floppy disk, and a hard disk. The storage medium 103 may be used to store an operating system (e.g., it may be executed by the main processor 101) and data generated during the operation of the operating system, a software program of an application software and data generated during the operation of the application software, and a software program of a dedicated module (e.g., it may be executed by a certain coprocessor 102) and data generated during the operation of the program. For example, in one embodiment of the present invention, the main processor 101 executes various functional applications and data processing by running a monitoring program stored in the storage medium 103. In some embodiments, the storage medium 103 may also be a remote memory (relative to a memory in the usual sense) remotely arranged relative to the main processor 101, and these remote memories may be connected to the main processor 101 or a certain coprocessor 102 via a network connection (e.g., via a network communication device 105). Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0075] The I / O (Input / Output) unit 104 includes an information input device and an information output device, which enables a user to interact with the electronic device 100. The input device can be used to receive input digital or character information, and specifically can include: a keyboard, a mouse, a joystick, a touch input device or a trackball, etc. The output device can be used to output / display a processing result processed by the electronic device 100, and the processing result can be made based on the information input by the input device. Specifically, the output device can include: a liquid crystal display (Liquid Crystal Display, LCD), an organic light-emitting diode (Organic Light-Emitting Diode, OLED), etc.
[0076] The network communication unit 105 realizes communication between the electronic device 100 and various remote devices through the connection of the wireless network, so that the electronic device 100 can also exchange data with the remote device (for example, the remote storage described above). Alternatively, the electronic device 100 can also realize connection with other electronic devices (for example, electronic devices with clients installed) through the network communication unit 105, so that the electronic device 100 can interact with other electronic devices as part of a large system.
[0077] Other expansion units 106 include a variety of peripheral components and interfaces thereof, so that the electronic device 100 can interact with a variety of devices. For example, through a Bluetooth interface, it can be connected to a Bluetooth headset, so that the audio played by the electronic device 100 can be received by the Bluetooth headset. For another example, through a bus interface (such as an RS-485 bus), the electronic device 100 can be connected to some sensors to obtain some monitoring data to assist the electronic device 100 in implementing specific functions. In various embodiments, other expansion interfaces 106 can exist alone or be integrated with other components of the electronic device 100. At the same time, other expansion interfaces 106 are optional, and their optional nature is represented in the figure by dotted lines.
[0078] The present invention also discloses a computer-readable storage medium, in which at least one computer instruction is stored. The at least one instruction is loaded and executed by a processor to implement the above method.
[0079] The present invention also discloses a computer program product, which includes a computer program / instruction. When the computer program / instruction is executed by a processor, the above method is implemented.
[0080] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0081] It should be noted that the sequence of the above embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0082] It should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the intention that the claimed invention requires more features than those expressly recited in each claim. Rather, as reflected in the claims, inventive aspects lie in less than all of the features of the individual embodiments previously disclosed. Therefore, the claims that follow the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present invention.
[0083] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0084] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims, any one of the claimed embodiments may be used in any combination.
Claims
1. A method for modifying a third-party library, characterized in that: include: Create an independent first library to store the modified classes; Copy the first class to be modified from the third-party library to the first library; modifying the first class in the first library to obtain a second class; Establishing a mapping relationship between the second class and the first class in the third-party library; During compilation, a first Transform API is inserted into the TransformTask chain, and the first Transform API replaces the first class with the second class when copying the third-party library.
2. The method according to claim 1, characterized in that The file names of the first category and the second category are consistent.
3. The method according to claim 1, characterized in that The step of modifying the first class in the first library to obtain the second class further includes: publishing the second class as an aar file.
4. The method according to claim 1, characterized in that The replacing the first category with the second category comprises: Traversing each library, obtaining all classes in one or more of the first libraries to form a modified class group; Each library is traversed again, and specific classes copied from the third-party library are refused according to the mapping relationship, where the specific classes refer to unmodified classes corresponding to the classes in the modified class group.
5. The method according to claim 1, characterized in that The step of modifying the first category in the first library to obtain the second category comprises: Keep the method names and variable names in the first class unchanged; Modify the method's logic; Modify the properties of methods and variables; Add new classes, methods, and variables.
6. A plug-in for modifying a third-party library, applied to an Android system, characterized in that: include: An editing module, used for creating an independent first library, then copying the first class to be modified from the third-party library to the first library, and modifying the first class in the first library to obtain the second class; The compile module replaces the first category with the second category when copying the third-party library according to the mapping relationship between the first category and the second category.
7. The plug-in according to claim 6, characterized in that The compilation module includes a first Transform API, which traverses each library twice when replacing the first class with the second class: During the first traversal, all classes in the first library are obtained to form a modified class group; During the second traversal, specific classes are refused to be copied from the third-party library according to the mapping relationship, where the specific classes refer to unmodified classes corresponding to the classes in the modified class group.
8. An electronic device, characterized in that: include: at least one memory for storing computer instructions; At least one processor, when the at least one processor executes the computer instructions, implements the method according to any one of claims 1 to 5.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one computer instruction, and the at least one instruction is loaded and executed by a processor to implement the method according to any one of claims 1 to 5.
10. A computer program product, characterized in that The computer program product comprises a computer program / instruction, and when the computer program / instruction is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
