A project access method, device, equipment and storage medium
By obtaining the path information of the mapping file and calling the corresponding function, external projects are injected into and integrated into the Android project, solving the problem of inconsistent content changes in multi-project sharing, and realizing the awareness of content changes and low-cost maintenance.
Patent Information
- Application Number
- CN202110191865.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-19
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2041-02-19
AI Technical Summary
In Android, when an external project is shared by multiple projects, changes to the project's content may not be recognized by projects that have not yet been updated, leading to inconsistencies in the shared content and resulting in functional integration issues.
By obtaining the file path information of the mapping file between the first project and the second project, the project injection function and access function are called to inject the first project into the second project, and the project injection and access are realized based on the mapping relationship, ensuring that the changes between the projects can be detected.
It enables the awareness of changes across multiple projects, resolves the functional integration issues caused by inconsistencies in shared content, and has low code maintenance costs.
Smart Images

Figure CN114968222B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the field of computer application, and particularly relate to a project access method and device, equipment and storage medium. BACKGROUND
[0002] When an external project in Android needs to be shared by at least two other projects, the current main implementation is in the form of a compiled library project. Specifically, the library project can be a project containing source code and resources, which can be referenced by other projects, so that the other projects use the code and resources contained therein. In actual application, the same library project can be accessed to at least two other projects.
[0003] However, the above sharing scheme has many defects. After a certain other project changes the content of the library project, if the other projects that also access the library project do not upgrade the version information of the library project, they will not be able to perceive the corresponding change content, which will lead to inconsistent sharing content between the other projects that access the same library project, and at this time, problems are prone to occur in functional docking. SUMMARY
[0004] Embodiments of the present application provide a project access method, device, equipment and storage medium, so that the second project that accesses the first project can directly perceive the effect of the change content in the first project.
[0005] In a first aspect, embodiments of the present application provide a project access method, which can include:
[0006] Obtaining file path information of a mapping file storing a mapping relationship between a business module in a first project and a second project, wherein the first project includes a project to be accessed to the business module;
[0007] Calling a project injection function that has been constructed to the first project on the second project by taking the file path information as a parameter, wherein the project injection function is used to inject the first project to the second project;
[0008] Calling a project access function that has been constructed to the business module by taking the file path information as a parameter, wherein the project access function is used to access the injected first project to the business module;
[0009] Wherein, the project injection function realizes the project injection function through the following steps:
[0010] If the mapping file exists under the file path information, the mapping file is introduced into the project environment where the second project is located, and the mapping relationship is obtained from the introduced mapping file;
[0011] The project path information of the first project and the module name of the business module are read from the mapping relationship, and the first project is injected into the second project corresponding to the module name based on the project path information.
[0012] In a second aspect, the embodiments of the present application further provide a project access device, which can include:
[0013] A file path information obtaining module is configured to obtain file path information of a mapping file storing a mapping relationship between a first project and a business module in a second project, wherein the first project includes a project to be accessed to the business module.
[0014] A project injection function calling module is configured to call a project injection function which has been constructed, with the file path information as a parameter, wherein the project injection function is configured to inject the first project into the second project.
[0015] A project access function calling module is configured to call a project access function which has been constructed, with the file path information as a parameter, wherein the project access function is configured to access the injected first project to the business module.
[0016] The project injection function calling module includes the following sub-modules.
[0017] A mapping relationship obtaining sub-module is configured to introduce the mapping file into a project environment where the second project is located, and obtain the mapping relationship from the introduced mapping file, if the mapping file exists under the file path information.
[0018] A first project injection sub-module is configured to read the project path information of the first project and the module name of the business module from the mapping relationship, and inject the first project into the second project corresponding to the module name based on the project path information.
[0019] In a third aspect, the embodiments of the present application further provide a project access device, which can include:
[0020] One or more processors;
[0021] A memory is configured to store one or more programs;
[0022] When the one or more programs are executed by the one or more processors, the one or more processors implement the project access method provided by any of the embodiments of the present application.
[0023] In a fourth aspect, the embodiments of the present application further provide a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the project access method provided by any of the embodiments of the present application.
[0024] The technical scheme of the embodiment of the present application acquires file path information of a mapping file storing a mapping relationship between a service module in a first project and a second project, wherein the first project comprises a project to be accessed to the service module; takes the file path information as a parameter, and calls a project injection function for injecting the first project to the second project, thereby realizing the injection dependency function of the first project to the second project; further, continues to take the file path information as a parameter, and calls a project access function for accessing the injected first project to the service module, thereby realizing the function of accessing the first project injected to the second project to a specific service module in the second project. It should be noted that the above-mentioned project injection function can realize the project injection function through the following steps: if the mapping file exists under the file path information, the mapping file is introduced into the project environment of the second project, the mapping relationship is acquired from the introduced mapping file, because only after the mapping file is introduced into the project environment, the reading and parsing of the mapping relationship stored in the mapping file can be realized; the project path information of the first project and the module name of the service module are read from the mapping relationship, and the first project is injected into the second project corresponding to the module name based on the project path information. The above-mentioned technical scheme describes a general external project access method in Android, which can effectively access the external project (i.e. the first project), and the external project can be simultaneously accessed to multiple current projects (i.e. the second project), when any one of the current projects changes the content of the external project, other current projects can directly perceive the changed content in the external project without updating, thereby effectively solving the problem that the shared content of each current project accessing the same external project is inconsistent, which leads to the problem of easy functional docking; and the code maintenance cost of the above-mentioned access method is low. BRIEF DESCRIPTION OF DRAWINGS
[0025] Figure 1 is a flow chart of a project access method in the embodiment one of the present application;
[0026] Figure 2 is a flow chart of a project access method in the embodiment two of the present application;
[0027] Figure 3 is a flow chart of a project access method in the embodiment three of the present application;
[0028] Figure 4 is a structural block diagram of a project access device in the embodiment four of the present application;
[0029] Figure 5 is a structural schematic diagram of a project access device in the embodiment five of the present application. DETAILED DESCRIPTION
[0030] The application will be described in further detail below with reference to the drawings and embodiments. It is to be understood that the specific embodiments described herein are merely illustrative of the application and are not to be used to limit the scope of the application. In addition, it should also be pointed out that, for the sake of description, only the parts related to the application are shown in the drawings and not all the structures.
[0031] Embodiment one
[0032] Figure 1 is a flowchart of a project access method provided in the first embodiment of the application. The embodiment can be applied to the case of accessing a first project to a second project, and is particularly applicable to the case that the second project, to which the first project is accessed, can directly perceive the change content in the first project. The method can be executed by a project access device provided in the embodiment of the application, the device can be realized by software and / or hardware, the device can be integrated on a project access equipment, and the project access equipment can be various user terminals or servers.
[0033] Referring to Figure 1 , the method of the embodiment of the application specifically includes the following steps:
[0034] S110, acquiring file path information of a mapping file storing a mapping relationship between a business module in a first project and a second project, wherein the first project includes a project to be accessed to the business module.
[0035] The second project is a project composed of at least one business module, the business module is a module capable of completing certain business functions, and the specific business functions are related to actual application scenarios, such as login function, viewing function, etc. In actual application, optionally, one business module can be composed of at least one class, the class can be composed of at least one method (i.e. function), and the method can be composed of multiple statements.
[0036] The mapping file stores a mapping relationship, which can be a relationship for describing the correspondence between the business module in the first project and the second project, and the relationship is defined based on a custom manner. In actual application, optionally, the second project can be referred to as a current project, and the first project can be referred to as an external project, because the external project can be a project to be accessed to the business module in the current project. On this basis, optionally, the number of current projects can be one, two or more, i.e. the external project can be simultaneously accessed to one, two or more current projects, the external project is simultaneously shared by the current projects, and the current projects can all change the content in the external project.
[0037] The file path information can be information of a path where the mapping file is located, and the mapping file can be found according to the file path information, that is, the mapping relationship in the mapping file can be found. In actual application, optionally, the mapping file can be a file set in a root directory, and the advantage of such setting is that subsequent reference of the dependency relationship can be quickly positioned to the mapping file, thereby improving the efficiency of compilation. Further optionally, the file name of the mapping file can be sourceCompile.gradle.
[0038] S120, taking the file path information as an input parameter, calling the project injection function that has been built, so that the project injection function executes S130-S140 according to the file path information.
[0039] Wherein, taking the file path information as an input parameter, calling the project injection function that has been built, the project injection function can find the mapping file according to the file path information, and introduce the mapping file into the project environment where the second project is located, and obtain the mapping relationship from the mapping file that has been introduced; further, it reads the project path information of the first project and the module name of the business module from the mapping relationship, and injects the first project into the second project corresponding to the module name based on the project path information, thereby realizing the analysis of the above-mentioned custom mapping relationship and the intelligent dependency injection effect. The specific implementation process of the project injection function is described as S130-S140.
[0040] In actual application, optionally, since the dependency relationship of the Android project is usually configured in the settings.gradle file, in order to facilitate management and unification, the project injection function can also be set in the settings.gradle file.
[0041] S130, if the mapping file exists under the file path information, the mapping file is introduced into the project environment where the second project is located, and the mapping relationship is obtained from the mapping file that has been introduced.
[0042] Wherein, first, it is judged whether the mapping file exists under the above-mentioned file path information, if not, it means that there is no need to perform external project dependency, at this time, it can be directly jumped out, without performing any processing, and the function flow ends; if yes, it means that the external project dependency needs to be performed, that is, the mapping relationship in the mapping file needs to be parsed. Specifically, the mapping file is introduced into the project environment where the second project is located, that is, the mapping file is introduced into the current environment where the current project is located, because only after the mapping file is introduced into the current environment, the reading and parsing of the mapping relationship stored in the mapping file can be realized. That is, after the mapping file is introduced into the current environment where the current project is located, the mapping relationship can be obtained from the mapping file that has been introduced into the current environment.
[0043] In practical applications, optionally, in order to achieve the above functions, a function can be defined first, and the specific definition of the function is as follows:
[0044] fun parase(){}
[0045] Among them, the function name of the function is parase, the return value is void, and then the specific business logic is completed in the custom function parase.
[0046] First, define a File file variable, and assume that the mapping file is stored in the root directory file named sourceCompile.gradle file, then you can call
[0047] File file=new File("sourceCompile.gradle")
[0048] Call the constructor of the File object to instantiate the file variable, and because the mapping file is set in the root directory file, the directory information does not need to be specified when initializing the file variable, which can improve the initialization efficiency of the file object.
[0049] Next, you can call
[0050] if(file.exists())
[0051] Function to determine whether the mapping file exists, and if so, the mapping file can be parsed next. Specifically, first call
[0052] apply from:file
[0053] Method to introduce the above custom mapping relationship into the current environment, only after being introduced into the current environment can the content in the above custom mapping relationship be read and parsed.
[0054] S140, read the project path information of the first project and the module name of the business module from the mapping relationship, and inject the first project into the second project corresponding to the module name based on the project path information.
[0055] The mapping relationship between the business modules in the first item and the second item can be represented in various ways, such as by the mapping relationship between the project path information of the first item and the module name of the business module. The project path information can be the information of the path where the first item is located, and the module name can be the name of the business module. Therefore, the project path information and the module name can be read from the mapping relationship. The first item can be found according to the project path information, and the second item corresponding to the module name can be found according to the module name. Then, the first item can be injected into the second item corresponding to the module name based on the project path information, thereby realizing the injection dependency function of the first item to the second item. It should be noted that the injection dependency function realized by this step is only to introduce the external item into the current item (i.e., the entire project engineering where the current item is located), and does not realize the dependency function of the external item to the specific business module. The dependency function of the external item to the business module will be completed by the following steps.
[0056] S150, taking the file path information as a parameter, calling the project access function that has been built, to access the injected first item to the business module.
[0057] The project access function can find the mapping file according to the file path information, and introduce the mapping file into the project environment where the second item is located, and obtain the mapping relationship from the introduced mapping file. Then, the module name of the business module in the second item to which the first item has been injected is read from the mapping relationship, and the injected first item is accessed to the business module corresponding to the module name based on the module name, thereby realizing the effect of accessing (i.e., depending) the first item that has been injected into the second item to the specific business module in the second item, that is, realizing the automatic dependency function of the business module to the external item.
[0058] In practical applications, the project access function can also be set in the build.gradle file, so that the dependency function of the business module can be realized in the build.gradle file where the specific business module is located.
[0059] The technical scheme of the embodiment of the present application obtains file path information of a mapping file storing a mapping relationship between a service module in a first project and a second project, wherein the first project comprises a project to be accessed to the service module; takes the file path information as a parameter, and calls a project injection function for injecting the first project to the second project, thereby realizing the injection dependency function of the first project to the second project; further, continues to take the file path information as a parameter, and calls a project access function for accessing the injected first project to the service module, thereby realizing the function of accessing the first project injected to the second project to the specific service module in the second project. It should be noted that the above-mentioned project injection function can realize the project injection function through the following steps: if the mapping file exists under the file path information, the mapping file is introduced into the project environment of the second project, the mapping relationship is obtained from the introduced mapping file, because only after the mapping file is introduced into the project environment, the mapping relationship stored in the mapping file can be read and parsed; the project path information of the first project and the module name of the service module are read from the mapping relationship, and the first project is injected into the second project corresponding to the module name based on the project path information. The above-mentioned technical scheme describes a general external project access method in Android, which can effectively access the external project (i.e. the first project), and the external project can be accessed to multiple current projects (i.e. the second project) at the same time, when any current project changes the content of the external project, other current projects can directly perceive the change content in the external project without updating, thereby effectively solving the problem that the shared content between the current projects accessing the same external project is inconsistent, which leads to the problem of easy functional docking; and the code maintenance cost of the above-mentioned access method is low.
[0060] On this basis, an optional technical scheme of injecting the first project into the second project corresponding to the module name based on the project path information can include: obtaining a target object to which the project path information is assigned and which has been constructed; setting a function based on the constructed project path information, assigning the target object to a project path information variable in the second project corresponding to the module name, so as to inject the first project into the second project. The target object can be a pre-constructed object, and the value of the target object is the project path information. The project path information setting function can be a pre-constructed function for setting the project path information, so that the target object can be assigned to the project path information variable in the second project corresponding to the module name based on the project path information setting function, so that the second project injects the corresponding first project into the second project according to the value of the project path information variable, thereby improving the convenience of project injection. For example, by calling
[0061] File targetFile = new File("${v}")
[0062] The method is used to construct a target object targetFile, wherein "${v}" is the project path information, i.e., the real path information of the external project. Then, the artifactid module (i.e., the business module corresponding to the module name) is added to the current project by calling
[0063] include":${artifactid}"
[0064] The artifactid module (i.e., the business module corresponding to the module name) is added to the current project, and the method is called again
[0065] project(":${artifactid}").projectDir = targetFile
[0066] The method is used to specify the project path information variable in the current project as the targetFile address.
[0067] Embodiment Two
[0068] Figure 2 is a flowchart of a project access method provided in Embodiment Two of the present application. The present embodiment is optimized on the basis of the technical solutions in the above embodiments. In the present embodiment, the mapping file is a file stored in the root directory of the second project, the ext code block is set in the mapping file, the mapping relationship is represented by the enableSource array set in the ext code block, and the enableSource array is divided by a preset identifier, so that the enableSource array is composed of the module name on one side of the preset identifier and the project path information on the other side. The explanations of the same or corresponding terms in the above embodiments are not repeated here.
[0069] Referring to Figure 2 , the method of the present embodiment can specifically include the following steps:
[0070] S210, obtaining file path information of a mapping file storing a mapping relationship between business modules in a first project and a second project, wherein the first project includes a project to be accessed to the business modules, the mapping file is a file stored in the root directory of the second project, an ext code block is set in the mapping file, the mapping relationship is represented by an enableSource array set in the ext code block, and the enableSource array is divided by a preset identifier, so that the enableSource array is composed of a module name on one side of the preset identifier and project path information on the other side.
[0071] The mapping file can be a file stored in the root directory of the second project, and an ext code block can be set in the mapping file, where ext can be understood as an extended file system (Extended file system), and the mapping relationship between the custom external project and the business module can be represented by an enableSource array set in the ext code block. The enableSource array can be segmented by a preset identifier, so that the segmented enableSource array is composed of a module name on one side of the preset identifier and project path information on the other side. In actual application, the preset identifier can be (:) optionally.
[0072] In order to better understand the construction process of the above mapping relationship, the above example will be taken as an example for illustrative description.
[0073] First, a mapping file named sourceCompile.gradle is created in the root directory of the external project. The reason for creating it in the root directory is to facilitate the subsequent reference of the dependency relationship to quickly locate the mapping file and thus improve the efficiency of compilation.
[0074] In the mapping file, an ext code block is defined, as follows: ext{
[0075] }
[0076] The ext code block represents the function of external dependency. Next, an enableSouce array is defined in the ext code block, which is defined as follows: ext{
[0077] enableSource=[ ]
[0079] }
[0080] The enableSouce array is used to describe the mapping relationship between multiple business modules and external projects in the subsequent description. Here, for the sake of convenience, only one business module is described as an example, and the specific dependency relationship is defined as follows:
[0081]
[0082] The dependency relationship is segmented by (:) on the left side, which represents the module name of the dependency, and on the right side, which represents the project path information of the external project corresponding to the module name. In actual application, the left side can be any name, but in order to effectively facilitate the subsequent automatic parsing of the business module to introduce the external project and improve the parsing efficiency, the name can be named in the form of (package name: module name).
[0083] S220, taking the file path information as an input parameter, calling the project injection function that has been constructed, so that the project injection function executes S230-S240 according to the file path information.
[0084] S230, if there is a mapping file under the file path information, introducing the mapping file into the project environment where the second project is located, and obtaining the mapping relationship from the introduced mapping file.
[0085] S240, reading the project path information of the first project and the module name of the business module from the mapping relationship, and injecting the first project into the second project corresponding to the module name based on the project path information.
[0086] S250, taking the file path information as an input parameter, calling the project injection function that has been constructed, so that the project injection function executes S230-S240 according to the file path information.
[0087] The technical scheme of the embodiment of the application, by the mapping file is stored in the root directory of the second project, the ext code block is set in the mapping file, the mapping relationship is represented by the enableSource array set in the ext code block, the enableSource array is divided by the preset identifier, so that the enableSource array is composed of the module name on one side of the preset identifier and the project path information on the other side, which helps to improve the convenience of extracting the project path information and the module name from the mapping relationship in the subsequent step.
[0088] On this basis, an optional technical scheme for reading the project path information of the first project and the module name of the business module from the mapping relationship can include: based on the preset identifier, the enableSource array is trained to obtain a training result, and key-value pair information is obtained from each training result; for each key-value pair information, the key information for representing the module name of the business module and the value information for representing the project path information of the first project are split from the key-value pair information; the module name is determined according to the key information and the project path information is determined according to the value information. Wherein, the preset identifier can be an identifier information for splitting the project path information and the module name in the mapping relationship, such as (:) and ( / ). The meaning of training is to traverse each element in the enableSource array, one training can obtain one training result (i.e. one element), and the training result can be represented by key-value pair information, wherein the key information in the key-value pair information can be used to represent the module name of the business module, and the value information in the key-value pair information can be used to represent the project path information of the first project, that is, the corresponding module name and project path information can be split from the key-value pair information.
[0089] To better understand the implementation process of the above technical solution, the following will continue to use the above example as an example for illustrative explanation.
[0090] By calling ext.enableSource
[0091] The method retrieves a custom array of `enableSource` objects (also known as an `enableSource` collection object), and then calls the `each` method on this `enableSource` collection object for polling. The specific implementation...
[0092] ext.enableSource.each{k,v->
[0093] }
[0094] In this round of training, each round of training is a key-value pair of information. The key information that is trained can be labeled as k, and the value information that is trained can be labeled as v. The module name is obtained from k, and the project path information is obtained from v.
[0095] Based on this, an optional technical solution is to represent the module name by package name X module name, where X represents a preset identifier; correspondingly, determining the module name based on the key information may include: segmenting the key information based on the preset identifier to obtain a segmented array; taking out the first array element in the segmented array and using the extracted result as the module name. Here, since the module name is composed of the combination of package name, X and module name, and X means a preset identifier, such as (:), ( / ), etc., the key information can be segmented based on the preset identifier to obtain a segmented array, and then the first array element in the segmented array can be taken as the module name, thereby achieving the effect of fast and accurate identification of the module name. For example, continuing with the above example, for the key information k, it can be obtained by calling String group = k.split(":")[0]
[0096] This method uses ":" as a separator for keys, resulting in a segmented array. The 0th element is then extracted and copied to a custom variable `group`, which stores the package name.
[0097] Similarly, call String artifactid = k.split(":")[1]
[0098] The method retrieves the first element and assigns it to the artifactid object, which is the module name of the business module when the external project is imported.
[0099] Example 3
[0100] Figure 3 is a flowchart of a project access method provided in Embodiment Three of the present application. The present embodiment is optimized on the basis of the technical solutions of the above-mentioned embodiments. In the present embodiment, the project access function realizes the project access function through the following steps: if there is a mapping file under the file path information, the mapping file is introduced into the project environment, and the mapping relationship is obtained from the introduced mapping file; the module name of the business module in the second project that has been injected into the first project is read from the mapping relationship, and the injected first project is accessed to the business module corresponding to the module name based on the module name. Wherein, the explanations of the same or corresponding terms as those in the above-mentioned embodiments are not repeated here.
[0101] Referring to Figure 3 , the method of the present embodiment can specifically include the following steps:
[0102] S310, obtain the file path information of the mapping file storing the mapping relationship between the business module in the first project and the second project, wherein the first project includes the project to be accessed to the business module.
[0103] S320, take the file path information as the input parameter, call the project injection function that has been constructed, so that the project injection function executes S330-S340 according to the file path information.
[0104] S330, if there is a mapping file under the file path information, the mapping file is introduced into the project environment where the second project is located, and the mapping relationship is obtained from the introduced mapping file.
[0105] S340, read the project path information of the first project and the module name of the business module from the mapping relationship, and inject the first project into the second project corresponding to the module name based on the project path information.
[0106] S350, take the file path information as the input parameter, call the project injection function that has been constructed, so that the project injection function executes S360-S370 according to the file path information.
[0107] S360, if there is a mapping file under the file path information, the mapping file is introduced into the project environment, and the mapping relationship is obtained from the introduced mapping file.
[0108] If not, it means that there is no need to perform the dependency of the external project, at this time, it can be directly jumped out, without performing any processing, and the function flow ends; if yes, it means that the dependency of the external project needs to be performed, that is, the mapping relationship in the mapping file needs to be parsed. Specifically, the mapping file is introduced into the project environment where the second project is located, that is, the mapping file is introduced into the current environment where the current project is located, because only after the mapping file is introduced into the current environment, the reading and parsing of the mapping relationship stored in the mapping file can be realized. That is, after the mapping file is introduced into the current environment where the current project is located, the mapping relationship can be obtained from the mapping file which has been introduced into the current environment.
[0109] S370, read the module name of the business module in the second project which has been injected into the first project from the mapping relationship, and connect the injected first project to the business module corresponding to the module name based on the module name.
[0110] The mapping relationship between the business modules in the first project and the second project can be represented in various ways, such as through the mapping relationship between the project path information of the first project and the module name of the business module. Therefore, the module name of the business module in the second project which has been injected into the first project can be read from the mapping relationship, and then based on the module, the first project which has been injected into the second project can be connected to the business module corresponding to the module name, thereby realizing the function of the dependency of the first project (i.e. the external project) to the specific business module.
[0111] For example, for the specific implementation process of reading the module name from the mapping relationship, continue to take the above example, by calling String artifactid=k.split(":")[1]
[0112] The method obtains the module name, and then calls implementation project("${artifactid}")
[0113] The method introduces the external project into the business module, thereby realizing the function of the automatic dependency of the business module to the external project.
[0114] The technical scheme of the embodiment of the application introduces the mapping file into the project environment if the mapping file exists under the file path information, and obtains the mapping relationship from the introduced mapping file, because the reading and analysis of the mapping relationship stored in the mapping file can be realized only after the mapping file is introduced into the project environment; then, the module name of the business module in the second project that has been injected into the first project is read from the mapping relationship, and the injected first project is connected to the business module corresponding to the module name based on the module name, so that the external project is introduced into the business module, thereby realizing the function of automatic dependence of the business module on the external project.
[0115] In order to better understand the specific implementation process of the above steps, the project connection method of the embodiment will be exemplarily described below in combination with the above examples.
[0116] Step one, customizing the mapping relationship between the external project and the business module
[0117] This step mainly describes a method for customizing the mapping relationship between the external project and the module name of the business module based on a custom mode, and the specific implementation is as follows:
[0118] Since the specific implementation process of this step is exemplarily described in S210 of Embodiment 2, it will not be described here.
[0119] Step two, realization of automatic introduction of the external project by the current project
[0120] This step is mainly used to parse the above customized mapping relationship and build the dependence relationship, and the specific implementation is as follows:
[0121] Since the dependence relationship of the Android project is usually configured in the settings.gradle file, a function can be encapsulated in the settings.gradle file to parse the above customized dependence rule and realize the intelligent dependence injection function, and the specific implementation method is as follows:
[0122] A function can be first customized, and the specific definition of the function is as follows:
[0123] fun parase(){}
[0124] The function name of the function is parase, and the return value is void. Next, the specific business logic is completed in the customized function parase.
[0125] First, define a File file variable, assuming that the mapping file is stored in the root directory under the file name sourceCompile.gradle, so you can call
[0126] File file = new File("sourceCompile.gradle")
[0127] Call the constructor of the File object to instantiate the file variable, because the mapping file is set in the root directory, so you do not need to specify the directory information when initializing the file variable, which can improve the efficiency of the file object initialization.
[0128] Next, you can call
[0129] if (file.exists())
[0130] Function to determine whether the mapping file exists, if so, you can parse the mapping file next. Specifically, first call
[0131] apply from: file
[0132] Method to introduce the above custom mapping relationship into the current environment, only after being introduced into the current environment can the content of the above custom mapping relationship be read and parsed.
[0133] Call
[0134] ext.enableSource
[0135] Method to get the custom enableSource array (also known as enableSource collection object), then call the each method on the enableSource collection object to loop, specifically
[0136] ext.enableSource.each {k, v ->
[0137] }
[0138] In the loop, each time the key-value pair information is looped, the looped key information can be marked as k, and the looped value information can be marked as v, then call
[0139] String group = k.split(":")[0]
[0140] The method is divided by key (":") and a split array is obtained. The 0th element is taken out and copied to the custom variable group, which stores the package name
[0141] Similarly, call
[0142] String artifactid=k.split(":")[1]
[0143] The method takes the 1st element and assigns it to the artifactid object, which is the module name of the business module when the external project is imported.
[0144] Then call
[0145] File targetFile=new File("${v}")
[0146] The method constructs a target object targetFile, where "${v}" is the project path information, i.e. the real path information of the external project. Then call
[0147] include":${artifactid}"
[0148] to add the artifactid module (i.e. the business module corresponding to the module name) to the current project, and call
[0149] project(":${artifactid}").projectDir=targetFile
[0150] to specify the project path information variable in the current project as targetFile address, thus completing the external project dependency function.
[0151] It should be noted that this step mainly completes the specified parsing and automatic injection of the main project. The injection only imports the external project into the entire project, and does not realize the dependency of the external project to the specific business module, so the next step is to describe how to realize the dependency function of the business module.
[0152] Step three, business module dependency function
[0153] This step mainly describes the dependency function of the business module. Step two solves the mapping relationship between the external project and the current project, and the dependency of the business module needs to be implemented in the build.gradle file of the specific business module.
[0154] First define a File file variable, assuming that the mapping file is stored in the root directory under the file name sourceCompile.gradle, …, the content in "…" is consistent with the content in the corresponding position in step two, and will not be described here.
[0155] Then call the each method of the enableSource collection object for round training, and the specific implementation is
[0156] ext.enableSource.each{k,v->
[0157] }
[0158] Then call
[0159] String artifactid=k.split(":")[1]
[0160] The method takes the first element and assigns it to the artifactid object, which is the module name of the business module when the external project is introduced. Then call
[0161] implementation project("${artifactid}")
[0162] The method introduces the external project into the business module, thereby realizing the function of automatic dependence of the business module on the external project.
[0163] The above technical solution can effectively access the external project (i.e. the first project), and the external project can be simultaneously accessed to multiple current projects (i.e. the second project). When any current project makes content changes to the external project, other current projects can directly perceive the change content in the external project without updating, thereby effectively solving the problem of inconsistent shared content between the current projects accessing the same external project, which leads to the problem of easy functional docking. Moreover, the code maintenance cost of the above access method is low.
[0164] Embodiment four
[0165] Figure 4 The structural block diagram of the project access device provided by the fourth embodiment of the application is provided. The device is used to execute the project access method provided by any of the above embodiments. The device and the project access method of the above embodiments belong to the same inventive concept. The details not described in the embodiment of the project access device can be referred to the embodiment of the project access method. See Figure 4The apparatus can specifically include a file path information acquisition module 410, a project injection function calling module 420, and a project access function calling module 430. The project injection function calling module 420 can include a mapping relationship acquisition submodule 4201 and a first project injection submodule 4202.
[0166] The file path information acquisition module 410 is configured to acquire file path information of a mapping file in which a mapping relationship between a business module and a first project is stored, the first project including a project to be accessed to the business module.
[0167] The project injection function calling module 420 is configured to call a project injection function that has been constructed, with the file path information as a parameter, the project injection function being configured to inject the first project to the second project.
[0168] The project access function calling module 430 is configured to call a project access function that has been constructed, with the file path information as a parameter, the project access function being configured to access the injected first project to the business module.
[0169] The project injection function calling module 420 includes the following submodules.
[0170] The mapping relationship acquisition submodule 4201 is configured to, if the mapping file exists under the file path information, introduce the mapping file into a project environment of the second project, and acquire the mapping relationship from the introduced mapping file. The first project injection submodule 4202 is configured to read project path information of the first project and a module name of the business module from the mapping relationship, and inject the first project into the second project corresponding to the module name based on the project path information.
[0171] Optionally, the mapping file is a file stored in a root directory of the second project, and an ext code block is set in the mapping file. The mapping relationship is represented by an enableSource array set in the ext code block. The enableSource array is divided by a preset identifier, so that the enableSource array is composed of a module name on one side of the preset identifier and project path information on the other side.
[0172] On this basis, the first project injection submodule 4202 can specifically include:
[0173] The key-value pair information obtaining unit is configured to obtain a result of the polling based on the preset identifier, and obtain key-value pair information from each polling result; the key-value pair information splitting unit is configured to split, for each key-value pair information, key information representing a module name of a business module and value information representing project path information of the first item from the key-value pair information; and the information determining unit is configured to determine the module name according to the key information and determine the project path information according to the value information.
[0174] On this basis, the module name is represented by a package name X module name, where X represents the preset identifier; and the information determining unit can specifically include:
[0175] The split array obtaining subunit is configured to split the key information based on the preset identifier to obtain a split array; and the module name taking out subunit is configured to take out a first array element in the split array and take the result as the module name.
[0176] Optionally, the first item injection sub-module 4202 can specifically include:
[0177] The target object obtaining unit is configured to obtain a target object that has been constructed and is assigned with the project path information; and the first item injection unit is configured to set a function based on the constructed project path information, assign the target object to a project path information variable in a second item corresponding to the module name, so as to inject the first item into the second item.
[0178] Optionally, the project access function calling 430 module includes the following sub-modules:
[0179] The mapping file introduction sub-module is configured to introduce a mapping file into a project environment if the mapping file exists under the file path information, and obtain a mapping relationship from the introduced mapping file; the first item access sub-module is configured to read, from the mapping relationship, a module name of a business module in a second item that has been injected with the first item, and access the injected first item to the business module corresponding to the module name based on the module name.
[0180] Optionally, the project injection function is set in a settings.gradle file, and / or the project access function is set in a build.gradle file.
[0181] The project access device provided in the fourth embodiment of the present application comprises a file path information acquisition module, a project injection function calling module, and a project access function calling module. The file path information acquisition module acquires file path information of a mapping file in which a mapping relationship between a service module in a first project and a service module in a second project is stored, wherein the first project comprises a project to be accessed to the service module. The project injection function calling module calls a project injection function, which is used to inject the first project to the second project, by taking the file path information as an input parameter, thereby realizing the injection dependency function of the first project to the second project. Then, the project access function calling module continues to call a project access function, which is used to access the injected first project to the service module, by taking the file path information as an input parameter, thereby realizing the function of accessing the first project, which has been injected to the second project, to the specific service module in the second project. It should be noted that the project injection function calling module can specifically comprise a mapping relationship acquisition submodule and a first project injection submodule. If the mapping file exists under the file path information, the mapping relationship acquisition submodule introduces the mapping file into the project environment of the second project, and acquires the mapping relationship from the introduced mapping file, because the mapping relationship stored in the mapping file can be read and parsed only after the mapping file is introduced into the project environment. The first project injection submodule reads the project path information of the first project and the module name of the service module from the mapping relationship, and injects the first project into the second project corresponding to the module name based on the project path information. The general external project access method in Android described in the above device can effectively access the external project (i.e. the first project), and the external project can be simultaneously accessed to multiple current projects (i.e. the second project). When the content of the external project is changed by any one of the current projects, the other current projects can directly perceive the changed content in the external project without updating, thereby effectively solving the problem that the shared content between the current projects accessing the same external project is inconsistent, which leads to the problem of easy functional docking. Moreover, the code maintenance cost of the above access method is low.
[0182] The project access device provided in the embodiments of the present application can execute the project access method provided in any of the embodiments of the present application, and has the corresponding function modules and beneficial effects of the execution method.
[0183] It should be noted that in the embodiments of the above project access device, each unit and module included is only divided according to the function logic, but is not limited to the above division, as long as the corresponding function can be realized. In addition, the specific names of each functional unit are only for easy mutual differentiation, and do not limit the protection scope of the present application.
[0184] Embodiment five
[0185] Figure 5 FIG. 5 is a structural schematic diagram of a project access device according to an embodiment of the present application; Figure 5 The project access device includes a memory 510, a processor 520, an input device 530, and an output device 540. The number of processors 520 in the project access device can be one or more, Figure 5 and one processor 520 is taken as an example in the description; the memory 510, the processor 520, the input device 530, and the output device 540 in the project access device can be connected through a bus or other means, Figure 5 and the connection through the bus 550 is taken as an example in the description.
[0186] The memory 510, as a computer readable storage medium, can be used to store software programs, computer executable programs, and modules, such as program instructions / modules corresponding to the project access method in the embodiment of the present application (for example, the file path information acquisition module 410, the project injection function calling module 420, and the project access function calling module 430 in the project access device, wherein the project injection function calling module 520 can include a mapping relationship acquisition submodule 4201 and a first project injection submodule 4202). The processor 520 executes the software programs, instructions, and modules stored in the memory 510, thereby performing various functional applications and data processing of the project access device, that is, implementing the project access method described above.
[0187] The memory 510 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and application programs required by at least one function; the data storage area can store data created according to the use of the project access device, etc. In addition, the memory 510 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some examples, the memory 510 can further include a memory remotely arranged with respect to the processor 520, and these remote memories can be connected to the device through a network. Examples of the above network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0188] The input device 530 can be used to receive input digital or character information, and to generate key signal inputs related to the user settings and function control of the device. The output device 540 can include a display device such as a display screen.
[0189] Embodiment six
[0190] The embodiment six of the present application provides a storage medium containing computer executable instructions, which, when executed by a computer processor, are used to execute a project access method, the method comprising:
[0191] Obtain file path information of a mapping file storing a mapping relationship between a first item and a business module in a second item, wherein the first item comprises an item to be accessed to the business module;
[0192] Call the built project injection function with the file path information as a parameter, wherein the project injection function is used to inject the first item to the second item;
[0193] Call the built project injection function with the file path information as a parameter, wherein the project injection function is used to inject the first item to the second item;
[0194] The project injection function realizes the project injection function through the following steps:
[0195] If the mapping file exists under the file path information, the mapping file is introduced into the project environment of the second item, and the mapping relationship is obtained from the introduced mapping file;
[0196] The project path information of the first item and the module name of the business module are read from the mapping relationship, and the first item is injected into the second item corresponding to the module name based on the project path information.
[0197] Of course, the storage medium provided by the embodiment of the application contains computer executable instructions, which are not limited to the method operations described above, and can also perform related operations in the project access method provided by any embodiment of the application.
[0198] From the above description of the embodiments, those skilled in the art can clearly understand that the application can be realized by means of software and necessary general hardware, and of course can also be realized by hardware, but in many cases the former is a better embodiment. According to such understanding, the technical solutions of the application can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a floppy disk, a read-only memory (ROM), a random access memory (RAM), a FLASH, a hard disk or an optical disk, etc., including a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in various embodiments of the application.
[0199] Note that the above merely describes preferred embodiments of the present application and the principles of the technology applied. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, modifications and substitutions can be made without departing from the scope of the present application. Therefore, although the present application has been described in detail through the above embodiments, the present application is not limited to the above embodiments, and can include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the claims.
Claims
1. A project access method, characterized by, The method comprises the following steps: obtaining file path information of a mapping file storing a mapping relationship between a first item and a business module in a second item, wherein the first item comprises an item to be accessed to the business module; and the second item is an item composed of at least one business module; calling a built project injection function with the file path information as an input parameter, wherein the project injection function is used to inject the first item to the second item; calling a built project access function with the file path information as an input parameter, wherein the project access function is used to access the injected first item to the business module; wherein the project injection function realizes the project injection function through the following steps: if the mapping file exists under the file path information, introducing the mapping file into a project environment of the second item, and obtaining the mapping relationship from the introduced mapping file; reading project path information of the first item and a module name of the business module from the mapping relationship, and injecting the first item into the second item corresponding to the module name based on the project path information; the mapping file is a file stored in a root directory of the second item, and an ext code block is set in the mapping file, the mapping relationship is represented by an enableSource array set in the ext code block, and the enableSource array is divided by a preset identifier, so that the enableSource array is composed of the module name on one side of the preset identifier and the project path information on the other side.
2. The method of claim 1, wherein, the reading of the project path information of the first item and the module name of the business module from the mapping relationship comprises: polling the enableSource array based on the preset identifier to obtain polling results, and obtaining key-value pair information from each polling result; for each key-value pair information, splitting the key information representing the module name of the business module and the value information representing the project path information of the first item from the key-value pair information; determining the module name according to the key information and determining the project path information according to the value information.
3. The method of claim 2, wherein, the module name is represented by a package name X module name, wherein the X represents the preset identifier; correspondingly, the determination of the module name according to the key information comprises: segmenting the key information based on the preset identifier to obtain a segmentation array; taking the first array element in the segmentation array as the module name.
4. The method of claim 1, wherein, the injection of the first item into the second item corresponding to the module name based on the project path information comprises: obtaining a target object with the project path information assigned; Based on the project path information setting function that has been constructed, the target object is assigned to the project path information variable in the second project corresponding to the module name, so as to inject the first project into the second project.
5. The method of claim 1, wherein, The project access function realizes the project access function through the following steps: If the mapping file exists under the file path information, the mapping file is introduced into the project environment, and the mapping relationship is obtained from the introduced mapping file; The module name of the business module in the second project that has been injected with the first project is read from the mapping relationship, and the injected first project is accessed to the business module corresponding to the module name based on the module name.
6. The method of claim 1, wherein, The project injection function is set in the settings.gradle file, and / or the project access function is set in the build.gradle file.
7. An item access device characterized by, Comprise: A file path information acquisition module for acquiring file path information of a mapping file storing a mapping relationship between a business module in a first project and a second project, wherein the first project comprises a project to be accessed to the business module; wherein the second project is a project composed of at least one business module; A project injection function calling module for calling a constructed project injection function with the file path information as a parameter, wherein the project injection function is used to inject the first project into the second project; A project access function calling module for calling a constructed project access function with the file path information as a parameter, wherein the project access function is used to access the injected first project to the business module; The project injection function calling module comprises the following sub-modules: A mapping relationship acquisition sub-module for introducing the mapping file into the project environment where the second project is located if the mapping file exists under the file path information, and acquiring the mapping relationship from the introduced mapping file; A first project injection sub-module for reading the project path information of the first project and the module name of the business module from the mapping relationship, and injecting the first project into the second project corresponding to the module name based on the project path information; The mapping file is a file stored in the root directory of the second project, and an ext code block is set in the mapping file. The mapping relationship is represented by an enableSource array set in the ext code block. The enableSource array is divided by a preset identifier, so that the enableSource array is composed of a module name on one side of the preset identifier and project path information on the other side.
8. An item access device characterized by, Comprise: One or more processors; Memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the project access method of any one of claims 1-6.
9. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program, when executed by a processor, implements the item access method of any one of claims 1-6.