Method, device, equipment and medium for configuring dynamic link library based on multi-process

By creating an independent process for each functional module in the Android application and copying the dynamic link file to a private directory, the problem of conflicting dependent libraries with the same name in the Android application is solved, ensuring the stable operation and independent functions of the APP and avoiding version conflicts. and compete for resources.

CN118409786BActive Publication Date: 2024-08-30HANGZHOU LIFESMART TECH
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410890400.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-04
Publication Date
2024-08-30
Estimated Expiration
2044-07-04

AI Technical Summary

Technical Problem

When Android applications are connected to third-party products, it is difficult to solve the problem of dependency library conflicts. In particular, conflicts with dynamic link libraries of the same name cause the APP to run abnormally. Existing technologies require modifications by dependency providers or the use of gradle's pickFirst command, resulting in version conflicts and functionality. Modules cannot work simultaneously.

Method used

By monitoring multiple functional modules running the application on the terminal device, an independent process is created, and the preset dynamic link file copy function is used to copy the dynamic link file in the original resource directory to the private directory of the application, so that each process Load the specific version of the so library it requires to avoid conflicts with dependent libraries with the same name.

Benefits of technology

It achieves the normal operation of dependency files with the same name without relying on dependency providers, avoids abnormal operation of APP due to dependencies with the same name, improves the stability and independent operation efficiency of APP functional modules, and reduces inter-process resources. Competition and Security Risks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409786B
    Figure CN118409786B
Patent Text Reader

Abstract

The present invention relates to the field of application process control technology, and discloses a method, device, equipment and medium for configuring a dynamic link library based on multiple processes. When monitoring multiple target running functions currently executed simultaneously by a target application, the present invention creates a target process corresponding to each target running function; and simultaneously calls a preset dynamic link file copy function to copy all dynamic link files under the original resource directory to the private directory of the target application, so that the target application can simultaneously implement the corresponding target running function through each target process. The present invention creates different processes for different functions, and the processes are independent of each other. Different dependent files are enabled through different processes, so that each process can independently load and use the required dynamic link file version, and even if there are dependent files with the same name, the stable operation of the functional modules of the APP application can be guaranteed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of application process control, and in particular to a method, device, equipment and medium for configuring a dynamic link library based on multiple processes. Background Art

[0002] As Android applications connect to more third-party products, the number of dependent libraries that need to be introduced continues to increase. These dependent libraries may include but are not limited to Java classes, resource files, dynamic dependent libraries, etc. Therefore, conflicts are prone to occur between different dependent libraries, such as class conflicts, resource conflicts, dynamic link library conflicts, etc. Among them, dynamic link library conflicts (also known as so library conflicts) mainly occur when so libraries with the same name are used in different dependent libraries (that is, the same type of dependent library is named the same).

[0003] The common technical solutions to resolve so library conflicts are as follows: (1) Let the conflicting providers use the same NDK version when compiling and generating so libraries, or statically link the conflicting libraries when compiling so libraries. Disadvantages: The dependent provider is unwilling to cooperate in modifying the so file, the waiting time is too long, etc. (2) Use gradle's pickFirst command. The gradle pickFirst command only retains the first found so library file and packages it into the final APK. Other conflicting so files with the same name will be ignored and will not be packaged into the final APK. Because there is only one, there is no conflict with other dependent libraries. Disadvantages: When multiple dependent libraries require different versions of so files, the pickFirst method only retains the first so file, resulting in the inability to load another version of the so file. Only one so file with the same name can be loaded in the same process. Although the dependency conflict is resolved, the dependent libraries A and B cannot work normally at the same time in the same process, which ultimately causes the APP to run abnormally. Summary of the invention

[0004] In view of this, the present invention provides a method, apparatus, device and medium for configuring a dynamic link library based on multiple processes to solve the problem of how to ensure the normal dependency of dependent files with the same name without relying on the dependency provider, thereby avoiding abnormal operation of the APP due to the same-name dependency during operation.

[0005] In a first aspect, the present invention provides a method for configuring a dynamic link library based on multiple processes, which is applied to a terminal device, wherein the terminal device is pre-configured with an Android application project structure, wherein a plurality of dependent library files under an original resource directory of the Android application project structure respectively include corresponding dynamic link files, and a dependent library folder is pre-configured in a configuration file, and the method comprises:

[0006] When the target application is detected to be running, multiple target running functions currently being executed simultaneously by the target application are monitored; wherein the target application relies on the dependency libraries corresponding to each target running function when implementing each of the target running functions;

[0007] Create a target process corresponding to each of the target running functions, and call a preset dynamic link file copy function at the same time to copy all the dynamic link files under the original resource directory to the private directory of the target application, so that the target application can realize the corresponding target running function through each of the target processes at the same time.

[0008] When the application is running, this embodiment monitors multiple target running functions executed before, dynamically manages processes and their required dependent libraries, creates an independent target process for each functional module at runtime, and each process loads the specific version of the so library it requires, thereby avoiding the conflict of dependent libraries with the same name in the related technology. The preset dynamic link file copy function is used to copy the so library under the original resource directory to the private directory of the application, ensuring that each process can independently load and use the required so file version. Regardless of whether it is a dependent file with the same name, the stable operation of the functional modules of the APP application can be guaranteed.

[0009] In an optional implementation, calling a preset dynamic link file copy function to copy all dynamic link files in the original resource directory to a private directory of the target application program includes:

[0010] Call the preset dynamic link file copy function to obtain the private directory path of the target application;

[0011] and obtaining the file name of the dynamic link file, and generating a first dynamic link file name list;

[0012] and obtaining the file names of all dynamic links in the private directory of the target application according to the private directory path, and generating a second dynamic link file name list;

[0013] According to the first dynamic link file name list and the second dynamic link file name list, the dynamic link file to be copied is copied to the private directory of the target application according to the private directory path.

[0014] This embodiment obtains the private directory path of the target application by calling a preset dynamic link file copy function, generates a first dynamic link file name list and a second dynamic link file name list respectively, and copies the required dynamic link files to the private directory of the target application by comparing the first and second dynamic link file name lists, thereby ensuring that each target process can independently use the dynamic link library files it needs. Since each process has independent files in its private directory, resource competition between processes is effectively reduced.

[0015] In an optional implementation, copying the dynamic link file to be copied to the private directory of the target application according to the private directory path according to the first dynamic link file name list and the second dynamic link file name list includes:

[0016] Calling a preset file name comparison function to obtain a tag value corresponding to each dynamic link file name in the first dynamic link file name list; the tag value is used to indicate whether the corresponding dynamic link file name needs to be copied;

[0017] According to the mark value corresponding to the dynamic link file name, the dynamic link file marked as needing to be copied is copied to the private directory of the target application according to the private directory path.

[0018] This embodiment marks each dynamic link file name by calling a preset file name comparison function, thereby effectively screening out the dynamic link files that need to be copied. This not only simplifies the file copying process, but also avoids unnecessary file copying operations, saving storage space and system resources. Different dynamic link files are marked separately, thereby ensuring that only the dynamic link files required for the target application to run are copied, thereby improving the running efficiency of the target application.

[0019] In an optional implementation, copying the dynamic link file to be copied to the private directory of the target application according to the private directory path according to the first dynamic link file name list and the second dynamic link file name list includes:

[0020] Calling a preset file clearing function to clear all the dynamic link files in the private directory of the target application according to the second dynamic link file name list;

[0021] According to the private directory path, the files corresponding to each dynamic link file name in the first dynamic link file name list are copied to the private directory of the target application in sequence.

[0022] This embodiment copies the required dynamic link files according to the specified private directory path through the tag value, ensuring that the target process has an independent dynamic link library file in its private directory, avoiding resource competition between processes, and improving the independent operation efficiency of the process. Since each process runs the required independent files in its private directory, it also further reduces security risks and ensures the safety and reliability of the system.

[0023] In an optional implementation, the calling of a preset file name comparison function to obtain a tag value corresponding to each dynamic link file name in the first dynamic link file name list includes:

[0024] Calling a preset file name comparison function to read byte information of each dynamic link file name in the first dynamic link file name list as a first byte information set;

[0025] and reading byte information of each dynamic link file name in the second dynamic link file name list as a second byte information set;

[0026] And take the byte information in the second byte information set as the target reference byte and traverse the first byte information set; when there is any byte information in the first byte information set that is identical to the target reference byte, mark the byte information that is identical to the target reference byte as to be copied; mark the byte information in the first byte information set that is different from the target reference byte as not to be copied.

[0027] This embodiment determines the files that need to be copied by comparing the file name information in the dynamic link file name list one by one, thereby improving the accuracy of file copying. Moreover, the file name information is used as a comparison basis, and there is no need to compare the complete file. On the basis of accuracy, efficient comparison and search is guaranteed, reducing the waste of computing resources.

[0028] In an optional implementation, the preset dynamic link file copy function, the preset file clearing function, and the preset file name comparison function are all encapsulated in the same object instance;

[0029] The object instance also encapsulates a dynamic link loading function for loading a dynamic link file currently existing in the private directory of the target application so that the target process runs the corresponding target running function through the dynamic link file.

[0030] In this embodiment, an object instance is created, and all related functions, the preset dynamic link file copy function, the preset file clearing function, the dynamic link loading function, and the preset file name comparison function and data are concentrated in one object. When the object instance is called, the operation can be performed quickly, and if the relevant code of a specific function needs to be improved later, only the content in the same object instance needs to be modified, which will not affect the implementation of other function instances.

[0031] In a second aspect, the present invention provides a device for configuring a dynamic link library based on multiple processes, the device comprising:

[0032] A program monitoring module, used for monitoring multiple target running functions currently executed simultaneously by the target application when the target application is monitored to be running; wherein the target application relies on the dependency library corresponding to each target running function when implementing each of the target running functions;

[0033] The multi-process function running module is used to create a target process corresponding to each of the target running functions, and at the same time call a preset dynamic link file copy function to copy all the dynamic link files under the original resource directory to the private directory of the target application, so that the target application can realize the corresponding target running function through each of the target processes at the same time.

[0034] In a third aspect, the present invention provides a computer device comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the method based on multi-process configuration of a dynamic link library of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0035] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the method for configuring a dynamic link library based on multiple processes according to the first aspect or any corresponding embodiment thereof.

[0036] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the method for configuring a dynamic link library based on multiple processes according to the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0038] Figure 1 is a flowchart of a method for configuring a dynamic link library based on multiple processes according to an embodiment of the present invention;

[0039] Figure 2 is a schematic diagram of an Android project structure according to a method for configuring a dynamic link library based on multiple processes according to an embodiment of the present invention;

[0040] Figure 3 is another schematic diagram of an Android project structure according to a method for configuring a dynamic link library based on multiple processes according to an embodiment of the present invention;

[0041] Figure 4 is another schematic diagram of an Android project structure according to a method for configuring a dynamic link library based on multiple processes according to an embodiment of the present invention;

[0042] Figure 5 is a flow chart of another method for configuring a dynamic link library based on multiple processes according to an embodiment of the present invention;

[0043] Figure 6 is a structural block diagram of a device for configuring a dynamic link library based on multiple processes according to an embodiment of the present invention;

[0044] Figure 7 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0045] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0046] As the business of different enterprises develops, the number of dependency libraries that need to be introduced by Android APPs when connecting to more third-party products gradually increases. The dependency objects that may be included in these dependency libraries include but are not limited to Java classes, resource files, and dynamic link libraries (so libraries). Conflicts are prone to occur between different dependency libraries, such as class conflicts, resource conflicts, and dynamic link library conflicts. Among them, the reason for dynamic link library conflicts (so library conflicts) is that the same so libraries are used in different dependency libraries, that is, different versions of the same dependency library have the same name.

[0047] In the related art, there are two main ways to solve the above-mentioned conflict of dependency libraries with the same name. The first way can be to coordinate the conflicting dependency providers to let them use the same NDK version when compiling and generating so libraries, or to statically link the conflicting libraries when compiling so libraries. In this way, coordinating dependency providers (such as software companies) to modify their dependency libraries is often very unfeasible, and the dependency providers are unwilling to cooperate and the waiting time is too long. The second way can be to only retain the so library of one dependency library and remove the so libraries in other conflicting dependency libraries. For example, using the pickFirst command of gradle, the command allows the APP to only package the first so library into the final apk file if there is a conflicting so library when compiling and packaging. In this way, when multiple dependency libraries are rigidly dependent on different versions of so libraries, for example, dependency library A must use version 1.0 of the so library, and dependency library B must use version 1.1 of the so library. Since only one so library with the same name can be loaded in the same process, this solution will cause the APP to be unable to use dependency library A and dependency library B at the same time when running.

[0048] An embodiment of the present invention provides a method for configuring a dynamic link library based on multiple processes, which is applied to scenarios where applications need to integrate multiple third-party dependent libraries or scenarios where applications need to run multiple complex functional modules at the same time. By creating multiple target processes at runtime and copying and loading the corresponding version of the so library for each process, each process has an independent operating environment and the dependent libraries do not interfere with each other, so that the dependent dynamic link files can work at the same time, thereby ensuring the normal operation of the APP function.

[0049] According to an embodiment of the present invention, a method embodiment of a dynamic link library based on multi-process configuration is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0050] In this embodiment, a method for configuring a dynamic link library based on multiple processes is provided, which is applied to a terminal device. The terminal device is pre-configured with an Android application project structure. Multiple dependent library files under the original resource directory of the Android application project structure respectively include corresponding dynamic link files, and a dependent library folder is pre-configured in a configuration file. Figure 1 is a flow chart of a method for configuring a dynamic link library based on multiple processes according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:

[0051] Step S101, when the target application is monitored to be running, multiple target running functions currently being executed simultaneously by the target application are monitored; wherein, when the target application implements each of the target running functions, it relies on the dependency libraries corresponding to each of the target running functions.

[0052] It should be noted that the Android application project structure in this embodiment refers to the project directory structure created using the Android development tool when developing Android applications, which at least includes resource files (such as / res, / assets), configuration files (such as / build.gradle), and files storing source code (such as / src), etc.

[0053] In this embodiment, the original resource directory ( / assets / ) is used to store the original files required by the application, which are the dynamic link files included in multiple dependent library files in this implementation. The dynamic dependent files (so files) are loaded by the application program when it is running in the Android system to provide corresponding functions.

[0054] In the configuration file ( / build.gradle) of this embodiment, the dependent library folder is preconfigured. It can be understood that declaring dependent libraries in the build.gradle file can enable the Android application project structure to automatically manage dependencies and ensure that all library files required for project construction exist. Therefore, it is necessary to pre-configure the introduction of dependencies. Exemplarily, the introduction declaration in the configuration file can refer to the following format:

[0055] implementation 'D1';

[0056] implementation 'D2';

[0057] Among them, implementation is a keyword in the build.gradle file, which is used to declare the library that the project depends on, and D1 or D2 is the identifier of the specific dependent library file.

[0058] For example, the Android application project structure in this embodiment can refer to Figure 2 , where two dependency library folders D1 and D2 are set up in the / assets directory respectively, and in the build.gradle.kts file, different dependency library files of D1 and D2 are pre-configured according to the import declaration format.

[0059] Specifically, refer to Figure 3 , D1 contains the dynamic link file A.so, refer to Figure 4 , D2 also includes a dynamic link file A.so. It is worth noting that the dynamic link file A.so given in this embodiment is a dependent file with the same name, but A.so in D1 is essentially a version 1 file, and A.so in D2 is essentially a version 2 file.

[0060] It should be noted that the target application refers to the Android application being executed, that is, the application software installed and run by the user on the mobile device. The target application needs to implement multiple functions at runtime, and each function may rely on different third-party libraries. For example, a music playback application is currently executing music playback, but at this time the user opens the audio book channel and clicks on the audio book to play. Therefore, the two playback situations need to rely on the same dynamic dependency file for realizing playback, but in essence they are not the same running function. Therefore, this embodiment monitors the multiple target running functions currently executed simultaneously by the target application to determine the number of target processes that need to be created.

[0061] Step S102, create a target process corresponding to each of the target running functions, and simultaneously call a preset dynamic link file copy function to copy all the dynamic link files under the original resource directory to the private directory of the target application, so that the target application can simultaneously implement the corresponding target running function through each of the target processes.

[0062] It is understandable that the purpose of creating a target process corresponding to each target running function is to avoid conflicts between libraries with the same name. In the Android operating system, if different functions of the same application program simultaneously rely on library files with the same name but different versions, conflicts will occur. By creating an independent process for each target running function, it is possible to ensure that each process loads the specific version of the library file it needs, thereby ensuring the independence and stability of the Android application program function module. In this embodiment, the target process is created by the Android operating system in the terminal device.

[0063] It should be noted that the preset dynamic link file copy function refers to a function pre-defined in the program, which is used to copy the dynamic link file (so file) in the original resource directory to the private directory of the target application. By calling the preset dynamic link file copy function, it is ensured that when the application is running, each functional module can load the required dynamic link file from the private directory instead of directly loading it from the original resource directory.

[0064] It is understandable that the Android operating system has advanced permission management for the private directory of an application. Only the application itself can access files in its private directory. Therefore, the dynamic link file is copied from the original resource directory to the private directory of the target application, and the required library files are loaded through an independent process of each functional module. This is to prevent other applications or malware from modifying the required dynamic link files and improve the security of the Android system. At the same time, a separate process accesses a separate private directory of an application, and its access logic is clearer, which reduces the complexity of file loading and further improves the stability of program operation.

[0065] When the application is running, this embodiment monitors multiple target running functions executed before, dynamically manages processes and their required dependent libraries, creates an independent target process for each functional module at runtime, and each process loads the specific version of the so library it requires, thereby avoiding the conflict of dependent libraries with the same name in the related technology. The preset dynamic link file copy function is used to copy the so library under the original resource directory to the private directory of the application, ensuring that each process can independently load and use the required so file version. Regardless of whether it is a dependent file with the same name, the stable operation of the functional modules of the APP application can be guaranteed.

[0066] This embodiment also provides a method for configuring a dynamic link library based on multiple processes, which can be used for the above-mentioned terminal device. The process includes the following steps:

[0067] Step S501, when the target application is detected to be running, multiple target running functions currently being executed by the target application are monitored; wherein, when the target application implements each of the target running functions, it relies on the dependency library corresponding to each target running function. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.

[0068] Step S502, create a target process corresponding to each of the target running functions; and simultaneously call the preset dynamic link file copy function to copy all the dynamic link files under the original resource directory to the private directory of the target application, so that the target application can simultaneously realize the corresponding target running function through each of the target processes.

[0069] For details, please refer to Figure 5 , the above-mentioned simultaneous calling of a preset dynamic link file copy function to copy all the dynamic link files in the original resource directory to the private directory of the target application program includes:

[0070] Step S5021, calling a preset dynamic link file copy function to obtain a private directory path of the target application.

[0071] It should be noted that, in this embodiment, the preset dynamic link file copy function is substantially implemented in the form of source code, and the main function of the preset dynamic link file copy function is to process the copy operation of the dynamic link library file.

[0072] Specifically, when obtaining the private directory path of the target application, first determine whether the private directory of the application exists, and call the directory verification function to ensure the existence of the private directory. If it does not exist, create the private directory path. The example code of step S5031 in this embodiment is as follows:

[0073] val privateDir = File(privateDirPath);

[0074] FileUtils.createOrExistsDir(privateDir);

[0075] The code calls FileUtils.createOrExistsDir(privateDir) to ensure that the private directory exists. FileUtils.createOrExistsDir is one of the functions provided in the technical documentation or pre-written by developers. For example, if privateDirPath is / data / com.example.app / lib / , the above code will check and create the private directory.

[0076] Step S5022, and obtain the file name of the dynamic link file, and generate a first dynamic link file name list.

[0077] Specifically, in this embodiment, a list containing all dynamic link library file names that need to be copied is obtained to generate a first dynamic link file name list for representing all dynamic link library files required by the application.

[0078] Step S5023, obtaining the file names of all dynamic links in the private directory of the target application according to the private directory path, and generating a second dynamic link file name list.

[0079] Step S5024: According to the first dynamic link file name list and the second dynamic link file name list, the dynamic link file to be copied is copied to the private directory of the target application according to the private directory path.

[0080] Specifically, in this embodiment, all second dynamic link files in the private directory are obtained and checked, and compared with the first dynamic link file name in the Apk package. According to the comparison result, the dynamic link file to be copied is copied to the private directory of the target application according to the private directory path.

[0081] This embodiment obtains the private directory path of the target application by calling a preset dynamic link file copy function, generates a first dynamic link file name list and a second dynamic link file name list respectively, and copies the required dynamic link files to the private directory of the target application by comparing the first and second dynamic link file name lists, thereby ensuring that each target process can independently use the dynamic link library files it needs. Since each process has independent files in its private directory, resource competition between processes is effectively reduced.

[0082] Specifically, in one embodiment, step S5024 includes:

[0083] A1, calling a preset file name comparison function to obtain a tag value corresponding to each dynamic link file name in the first dynamic link file name list; the tag value is used to indicate whether the corresponding dynamic link file name needs to be copied.

[0084] A2, according to the mark value corresponding to the dynamic link file name, the dynamic link file marked as needing to be copied is copied to the private directory of the target application according to the private directory path.

[0085] This embodiment marks each dynamic link file name by calling a preset file name comparison function, thereby effectively screening out the dynamic link files that need to be copied. This not only simplifies the file copying process, but also avoids unnecessary file copying operations, saving storage space and system resources. Different dynamic link files are marked separately, thereby ensuring that only the dynamic link files required for the target application to run are copied, thereby improving the running efficiency of the target application.

[0086] The sample code of step A1 in this embodiment is as follows:

[0087] varneedToCopy=false

[0088] for (fileName in copyFileNames) {

[0089] val assetFilePath = "$assetPath${File.separator}$fileName"

[0090] val assetFileStream = context.assets.open(assetFilePath

[0091] val privateFile = File(privateDirPath, fileName)

[0092] if (!privateFile.exists() || !isFileContentSame(assetFileStream,FileInputStream(privateFile))) {

[0093] needToCopy = true break

[0094] }

[0095] }

[0096] Among them, first define the Boolean variable needToCopy as a mark value, with an initial value of false, which is used to indicate whether a file copy is needed. Use a for loop to traverse each file name fileName in the copyFileNames list. In the loop, construct assetFilePath, which is a path composed of assetPath, file separator and fileName. Use context.assets.open(assetFilePath) to open the resource file and assign it to assetFileStream. Create a File object privateFile to represent the corresponding file under the private directory path privateDirPath. Check whether privateFile exists or whether the contents of the original resource directory file stream and the private directory file stream are the same. If privateFile does not exist, set needToCopy to true and jump out of the loop. Through the needToCopy variable and the process of loop traversal, the dynamic link file is marked, and the file is copied only when necessary, avoiding repeated copying of files with the same content.

[0097] In an optional implementation, step A1 specifically includes: calling a preset file name comparison function to read the byte information of each dynamic link file name in the first dynamic link file name list as a first byte information set; and reading the byte information of each dynamic link file name in the second dynamic link file name list as a second byte information set; and using the byte information in the second byte information set as the target reference byte, traversing the first byte information set; when there is any byte information in the first byte information set that is identical to the target reference byte, marking the byte information that is identical to the target reference byte as to be copied; and marking the byte information in the first byte information set that is different from the target reference byte as not to be copied.

[0098] In an optional implementation manner of this embodiment, the specific example code of step A1 is as follows:

[0099] privatefunisFileContentSame(

[0100] inputStream1:InputStream,

[0101] inputStream2:FileInputStream):Boolean{

[0102] returninputStream1.use{input1->inputStream2.use{input2->input1.readBytes().contentEquals(input2.readBytes())

[0103] }

[0104] }

[0105] }

[0106] Among them, the isFileContentSame function receives two input parameters inputStream1 and inputStream2 (the input parameters in this embodiment are the first dynamic link file name list and the second dynamic link file name list), and uses the use function to ensure that the input stream will be properly closed after use, effectively avoiding resource leakage. In the use block, all bytes of the two input streams are read respectively and converted into byte arrays. The contentEquals method is used to compare the contents of the two byte arrays. If the two byte arrays are the same, the function returns true, otherwise it returns false.

[0107] This embodiment determines the files that need to be copied by comparing the file name information in the dynamic link file name list one by one, thereby improving the accuracy of file copying. Moreover, the file name information is used as a comparison basis, and there is no need to compare the complete file. On the basis of accuracy, efficient comparison and search is guaranteed, reducing the waste of computing resources.

[0108] The sample code of step A2 in this embodiment is as follows:

[0109] if (needToCopy) {

[0110] privateDir.listFiles { _, name ->name.endsWith(".so")}?,forEach {it.delete()}

[0111] for (fileName in copyFileNames)

[0112] { val assetsFileName = "$assetPath${File.separator}$fileName"

[0113] context.assets.open(assetsFileName).use { assetInputStream ->valprivateFile = File(privateDirPath, fileName)

[0114] FileOutputStream(privateFile).use { outputStream ->assetInputStream.copyTo(outputStream)

[0115] }

[0116] }

[0117] }

[0118] }

[0119] Among them, needToCopy is a tag value indicating whether the corresponding dynamic link file name needs to be copied. According to the judgment condition if (needToCopy), if needToCopy is true, then continue to perform subsequent operations, traverse each file name in the copyFileNames list (comparison result): construct assetsFileName, that is, the original resource directory address plus the file name, open the dynamic link file input stream assetInputStream corresponding to assetsFileName, create a file privateFile with a corresponding file name under the private directory path privateDirPath, use the file output stream outputStream to copy the content in the dynamic link file input stream to privateFile, and complete the entire process of copying the dynamic link file to be copied according to the private directory path to the private directory of the target application. The use statement mentioned above automatically manages the opening and closing of resources (input stream and output stream), simplifies the code copying process, is faster, and ensures the security of dynamic link file copying.

[0120] In another embodiment, step S5024 includes:

[0121] B1, calling a preset file clearing function to clear all the dynamic link files in the private directory of the target application according to the second dynamic link file name list.

[0122] B2. Copy the files corresponding to each dynamic link file name in the first dynamic link file name list to the private directory of the target application in sequence according to the private directory path.

[0123] In step B1 of this embodiment, the preset file clearing function can be used before step A2, and can also be used in the process of copying dynamic link files separately. The implementation process of its code only needs to write a preset file clearing function separately, wherein the main parameters of the preset file clearing function include: the private directory path of the target application and the extension of the dynamic link file to be cleared. The logic of the preset file clearing function can be to obtain the private directory path of the target application, list all files in the private directory, and filter out all files that meet the specific extension, traverse and delete all qualified files. The preset file clearing function returns a Boolean value, true: indicates that all qualified files are successfully deleted; false: indicates that an error occurs during the deletion process. The specific code example is not repeated here in this embodiment. When the preset file clearing function needs to be called, the preset file clearing function declaration is set before step A2, so as to clear the dynamic link files in the private directory in time after calling the preset file name comparison function, thereby reducing the occupation of memory resources.

[0124] In step B2 of this embodiment, it is only necessary to create a separate copy list, store all first dynamic link file name values ​​in a separate copy list, and copy them to the private directory of the target application in sequence according to the private directory path. The specific code examples will not be repeated in this embodiment.

[0125] This embodiment copies the required dynamic link files according to the specified private directory path through the tag value, ensuring that the target process has an independent dynamic link library file in its private directory, avoiding resource competition between processes, and improving the independent operation efficiency of the process. Since each process runs the required independent files in its private directory, it also further reduces security risks and ensures the safety and reliability of the system.

[0126] In an optional implementation, the preset dynamic link file copy function, the preset file clearing function, and the preset file name comparison function are all encapsulated in the same object instance;

[0127] The object instance also encapsulates a dynamic link loading function for loading a dynamic link file currently existing in the private directory of the target application so that the target process runs the corresponding target running function through the dynamic link file.

[0128] It should be noted that an object instance (such as DynamicSoLoadUtils) can be understood as a specific object created by a class, which contains a series of related functions and properties. The object instance in this embodiment encapsulates a preset dynamic link file copy function (such as copyContentFile), the preset file clearing function (such as clearOldFiles), a dynamic link loading function (such as System.load), and the preset file name comparison function (such as isFileContentSame). This object instance is specifically used to manage operations such as loading, comparing, copying, and clearing dynamic link files.

[0129] In addition, the dynamic link loading function is used to load the dynamic link file currently existing in the private directory of the target application. This function is a function that can be directly called in the technical documentation of the Android operating system itself.

[0130] The following is a code example of the dynamic link loading function used in this embodiment:

[0131] for(filenameincopyFileNames){

[0132] System.load(privateDirPath+File.separator+filename)

[0133] }

[0134] true

[0135] }catch(t:Throwable){

[0136] t.printStackTrace()

[0137] false

[0138] }

[0139] }

[0140] The code traverses each file name and loads the corresponding dynamic link file through the System.load function. If an exception occurs during the loading process, the exception is captured and printed to the run log. The function returns false, indicating that the loading failed.

[0141] In this embodiment, an object instance is created, and all related functions, the preset dynamic link file copy function, the preset file clearing function, the dynamic link loading function, and the preset file name comparison function and data are concentrated in one object. When the object instance is called, the operation can be performed quickly, and if the relevant code of a specific function needs to be improved later, only the content in the same object instance needs to be modified, which will not affect the implementation of other function instances.

[0142] According to the method of configuring dynamic link library based on multiple processes provided by this embodiment, when the App is running, when the function F1 is used, the process P1 is started. When the P1 process is initialized, the method in the object instance is called to copy A.so in the assets / D1 directory to the private directory of the App on the currently running device (for example, / data / com.example.app / D1, where com.example.app represents the package name of the App), and load the so. After the loading is completed, the function F1 can be used normally in the P1 process. If the function F2 is used, the same method is used to start the process P2. The two processes do not interfere with each other and are independent of each other, thereby realizing two different functions at the same time. The more functions there are, the more processes are started. This embodiment only takes two processes as an example for explanation, but is not limited to this.

[0143] In the present embodiment, a device based on multi-process configuration dynamic link library is also provided, and the device is used to implement the above-mentioned embodiment and preferred implementation mode, and the description has been made no further. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.

[0144] This embodiment provides a device for configuring a dynamic link library based on multiple processes, such as Figure 6 As shown, including:

[0145] The program monitoring module 601 is used to monitor multiple target running functions currently executed by the target application when the target application is monitored to be running; wherein, when the target application implements each of the target running functions, it relies on the dependency library corresponding to each of the target running functions;

[0146] The multi-process function running module 602 is used to create a target process corresponding to each of the target running functions, and at the same time call the preset dynamic link file copy function to copy all the dynamic link files under the original resource directory to the private directory of the target application, so that the target application can realize the corresponding target running function through each of the target processes at the same time.

[0147] In an optional implementation, the multi-process function running module 602 includes:

[0148] A private directory path acquisition unit, used to call a preset dynamic link file copy function to acquire a private directory path of a target application;

[0149] A first dynamic link file name list generating unit, used to obtain the file name of the dynamic link file and generate a first dynamic link file name list;

[0150] A second dynamic link file name list generating unit is used to obtain the file names of all dynamic links in the private directory of the target application according to the private directory path, and generate a second dynamic link file name list;

[0151] The file copying unit is used to copy the dynamic link file to be copied to the private directory of the target application according to the first dynamic link file name list and the second dynamic link file name list and the private directory path.

[0152] In an optional implementation, the file copying unit includes:

[0153] A file marking subunit is used to call a preset file name comparison function to obtain a marking value corresponding to each dynamic link file name in the first dynamic link file name list; the marking value is used to indicate whether the corresponding dynamic link file name needs to be copied;

[0154] The marking copy subunit is used to copy the dynamic link file marked as needing to be copied to the private directory of the target application according to the private directory path according to the marking value corresponding to the dynamic link file name.

[0155] In an optional implementation, the file copying unit includes:

[0156] A file clearing subunit is used to call a preset file clearing function to clear all the dynamic link files in the private directory of the target application according to the second dynamic link file name list;

[0157] The file complete copy subunit is used to copy the file corresponding to each dynamic link file name in the first dynamic link file name list to the private directory of the target application in sequence according to the private directory path.

[0158] In an optional embodiment, the file marking subunit includes: calling a preset file name comparison function to read the byte information of each dynamic link file name in the first dynamic link file name list as a first byte information set; and reading the byte information of each dynamic link file name in the second dynamic link file name list as a second byte information set; and traversing the first byte information set using the byte information in the second byte information set as the target reference byte; when there is any byte information in the first byte information set that is identical to the target reference byte, marking the byte information that is identical to the target reference byte as to be copied; and marking the byte information in the first byte information set that is different from the target reference byte as not to be copied.

[0159] In an optional implementation, the preset dynamic link file copy function, the preset file clearing function, and the preset file name comparison function are all encapsulated in the same object instance;

[0160] The object instance also encapsulates a dynamic link loading function for loading a dynamic link file currently existing in the private directory of the target application so that the target process runs the corresponding target running function through the dynamic link file.

[0161] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0162] The device based on multi-process configuration dynamic link library in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (APPlication Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0163] The embodiment of the present invention also provides a computer device having the above Figure 6 The device shown is based on a multi-process configuration dynamic link library.

[0164] See also Figure 7 , Figure 7 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 7 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 7 A processor 10 is taken as an example.

[0165] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0166] The memory 20 stores instructions executable by at least one processor 10, so that at least one processor 10 executes the method shown in the above embodiment.

[0167] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. 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.

[0168] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0169] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.

[0170] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0171] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0172] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the claims.

Claims

1. A method for configuring a dynamic link library based on multiple processes, characterized in that: Applied to a terminal device, the terminal device is pre-configured with an Android application project structure, a plurality of dependent library files under an original resource directory of the Android application project structure respectively include corresponding dynamic link files, and a dependent library folder pre-configured in a configuration file; The method comprises: When the target application is detected to be running, multiple target running functions currently being executed simultaneously by the target application are monitored; wherein the target application relies on the dependency libraries corresponding to each target running function when implementing each of the target running functions; Create a target process corresponding to each of the target running functions, and call a preset dynamic link file copy function at the same time to copy all the dynamic link files under the original resource directory to the private directory of the target application, so that the target application can realize the corresponding target running function through each of the target processes at the same time.

2. The method according to claim 1, characterized in that: The calling of the preset dynamic link file copy function to copy all the dynamic link files in the original resource directory to the private directory of the target application program specifically includes: Call the preset dynamic link file copy function to obtain the private directory path of the target application; and obtaining the file name of the dynamic link file, and generating a first dynamic link file name list; and obtaining the file names of all dynamic links in the private directory of the target application according to the private directory path, and generating a second dynamic link file name list; According to the first dynamic link file name list and the second dynamic link file name list, the dynamic link file to be copied is copied to the private directory of the target application according to the private directory path.

3. The method according to claim 2, characterized in that The step of copying the dynamic link file to be copied to the private directory of the target application according to the private directory path according to the first dynamic link file name list and the second dynamic link file name list specifically includes: Calling a preset file name comparison function to obtain a tag value corresponding to each dynamic link file name in the first dynamic link file name list; the tag value is used to indicate whether the corresponding dynamic link file name needs to be copied; According to the mark value corresponding to the dynamic link file name, the dynamic link file marked as needing to be copied is copied to the private directory of the target application according to the private directory path.

4. The method according to claim 2, characterized in that: The step of copying the dynamic link file to be copied to the private directory of the target application according to the private directory path according to the first dynamic link file name list and the second dynamic link file name list specifically includes: Calling a preset file clearing function to clear all the dynamic link files in the private directory of the target application according to the second dynamic link file name list; According to the private directory path, the files corresponding to each dynamic link file name in the first dynamic link file name list are copied to the private directory of the target application in sequence.

5. The method according to claim 3 or 4, characterized in that: Calling a preset file name comparison function to obtain a tag value corresponding to each dynamic link file name in the first dynamic link file name list specifically includes: Calling a preset file name comparison function to read byte information of each dynamic link file name in the first dynamic link file name list as a first byte information set; and reading byte information of each dynamic link file name in the second dynamic link file name list as a second byte information set; And take the byte information in the second byte information set as the target reference byte and traverse the first byte information set; when there is any byte information in the first byte information set that is identical to the target reference byte, mark the byte information that is identical to the target reference byte as to be copied; mark the byte information in the first byte information set that is different from the target reference byte as not to be copied.

6. The method according to claim 5, characterized in that The preset dynamic link file copy function, the preset file clearing function, and the preset file name comparison function are all encapsulated in the same object instance; The object instance also encapsulates a dynamic link loading function for loading a dynamic link file currently existing in the private directory of the target application so that the target process runs the corresponding target running function through the dynamic link file.

7. A device for configuring a dynamic link library based on multiple processes, characterized in that: Applied to a terminal device, the terminal device is pre-configured with an Android application project structure, the dependent library files under the original resource directory of the Android application project structure respectively include corresponding dynamic link files, and the dependent library folder is pre-configured in the configuration file; The device comprises: A program monitoring module, used for monitoring multiple target running functions currently executed simultaneously by the target application when the target application is monitored to be running; wherein the target application relies on the dependency library corresponding to each target running function when implementing each of the target running functions; The multi-process function running module is used to create a target process corresponding to each of the target running functions, and at the same time call a preset dynamic link file copy function to copy all the dynamic link files under the original resource directory to the private directory of the target application, so that the target application can realize the corresponding target running function through each of the target processes at the same time.

8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method based on multi-process configuration dynamic link library according to any one of claims 1 to 6 by executing the computer instructions.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method for configuring a dynamic link library based on multiple processes according to any one of claims 1 to 6.

10. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to enable a computer to execute the method for configuring a dynamic link library based on multiple processes according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Packing method for front-end programming items and electronic device

    CN109324881A

  • Method and device for calling resource file by application

    CN111400256A

  • Application software package generation method and device, computer equipment and storage medium

    CN114527987A

  • Application program hot update method and device based on Android system

    CN116594644A

  • Process configuration method and system for plug-in data processing software

    CN117407048A