Visualization method of Android dependency relationship
Generating a dependency diagram through Gradle dynamic query and visualization methods, solving the problem of difficult management of dependency library relationships in Android projects, realizing the optimization of dependency library and the improvement of compilation and construction speed.
Patent Information
- Application Number
- CN202411233187.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-04
- Publication Date
- 2024-12-27
AI Technical Summary
In existing Android engineering code, the relationship between dependencies is difficult to manage, resulting in limited speed of componentized solutions optimization and compilation and construction.
Generate dependency graphs through Gradle dynamic query and visualization methods, including establishing Gradle tasks, initializing treeMap, traversing project structure, collecting and removing redundant dependencies, generating .dot files and converting them to PNG images, using Mermaid Live Editor and Graphviz tools Conduct visual display.
Effectively manage dependency libraries, optimize component solutions, and significantly accelerate the compilation and construction speed of Android applications.
Smart Images

Figure CN119201122A_ABST
Abstract
Description
Technical Field
[0001] The invention discloses a visualization method for Android dependency relationships and relates to the field of mobile applications. Background Art
[0002] Most of the current Android project codes are componentized structures, including many basic capability libraries and business libraries. The dependency relationships between so many dependent libraries and between dependent libraries and shell projects are mostly sorted out through manual analysis, which is not conducive to users to better manage various dependent libraries, optimize componentization solutions, and speed up the compilation and construction of Android applications. Summary of the invention
[0003] In view of the problems of the prior art, the present invention provides a method for visualizing Android dependencies, which dynamically queries the relationships between all dependent libraries based on Gradle and displays them visually, so as to facilitate users to better manage various dependent libraries, optimize componentization solutions, and speed up the compilation and construction of Android applications.
[0004] The specific scheme proposed by the present invention is:
[0005] The present invention provides a method for visualizing Android dependency relationships, comprising:
[0006] Create a Gradle task to specify the format of dependency output for visualizing project dependencies, including:
[0007] Execute the Graph task: initialize the treeMap, create a LinkedHashMap to store all modules and their dependencies,
[0008] Traverse the project structure, starting from the rootProject, and use the queue breadth-first traversal of all subprojects. For each subproject, call the collection function to collect the current module, and traverse all dependencies of the current module, collect dependencies, and add the current module and its dependencies to the dependency node list of the current project.
[0009] Traverse all modules in treeMap and remove redundant dependencies.
[0010] Generate .dot file: Generate a .dot file in graph TD syntax, save the dependency relationship in the form of a graph to the project.dot file, or generate a .dot file in digraph syntax, save the dependency relationship in the form of a directed graph, and save it to the project_digraph.dot file,
[0011] Generate PNG image: Convert .dot files to PNG image files.
[0012] Output the path of the .dot file and convert the dot file into a visual graphic through the Mermaid Live Editor service.
[0013] Furthermore, in the Android dependency visualization method, a ModuleNode class is defined to represent a dependency node list. The ModuleNode class includes two attributes, namely, a module name and a dependency relationship of the current module.
[0014] Furthermore, when removing redundant dependencies in the Android dependency visualization method: traverse the dependency node list of the current module, and determine whether a dependency node can be indirectly dependent through other dependency nodes. If so, remove the dependency node from the dependency list.
[0015] Furthermore, when generating a PNG image in the Android dependency visualization method, a Graphviz tool is used to convert a .dot file into a PNG image file.
[0016] The present invention provides a visualization device for Android dependency relationships, including a Gradle task management module,
[0017] The Gradle task management module establishes a Gradle task and specifies the format of dependency output for visualizing project dependencies, including:
[0018] Execute the Graph task: initialize the treeMap, create a LinkedHashMap to store all modules and their dependencies,
[0019] Traverse the project structure, starting from the rootProject, and use the queue breadth-first traversal of all subprojects. For each subproject, call the collection function to collect the current module, and traverse all dependencies of the current module, collect dependencies, and add the current module and its dependencies to the dependency node list of the current project.
[0020] Traverse all modules in treeMap and remove redundant dependencies.
[0021] Generate .dot file: Generate a .dot file in graph TD syntax, save the dependency relationship in the form of a graph to the project.dot file, or generate a .dot file in digraph syntax, save the dependency relationship in the form of a directed graph, and save it to the project_digraph.dot file,
[0022] Generate PNG image: Convert .dot files to PNG image files.
[0023] Output the path of the .dot file and convert the dot file into a visual graphic through the Mermaid Live Editor service.
[0024] Furthermore, in the Android dependency visualization device, the Gradle task management module defines a ModuleNode class to represent a dependency node list. The ModuleNode class contains two attributes, namely, the module name and the dependency of the current module.
[0025] Furthermore, when removing redundant dependencies, the Gradle task management module of the Android dependency visualization device traverses the dependency node list of the current module and determines whether a dependency node can be indirectly dependent on other dependency nodes. If so, the dependency node is removed from the dependency list.
[0026] Furthermore, when the Gradle task management module of the Android dependency visualization device generates a PNG image, the Graphviz tool is used to convert the .dot file into a PNG image file.
[0027] The benefits of the present invention are:
[0028] The method of the present invention dynamically queries the relationship between all dependent libraries based on Gradle for visual display, which is convenient for users to better manage various dependent libraries, optimize componentization solutions, and speed up the compilation and construction of Android applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 It is a schematic flow chart of the method of the present invention. DETAILED DESCRIPTION
[0030] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0031] Example 1
[0032] The present invention provides a method for visualizing Android dependency relationships, comprising:
[0033] Create a Gradle task to specify the format of dependency output for visualizing project dependencies, including:
[0034] Execute the Graph task: initialize the treeMap, create a LinkedHashMap to store all modules and their dependencies,
[0035] Traverse the project structure, starting from rootProject, and use the queue breadth-first traverse all subprojects. For each subproject, call the collectModuleNodes collection function to collect the current module, and traverse all dependencies of the current module, collect dependencies, and add the current module and its dependencies to the dependency node list of the current project. The ModuleNode class can be defined to represent the dependency node list. The ModuleNode class contains two attributes, namely the module name moduleName and the dependency of the current module dependencyNode.
[0036] Traverse all modules in treeMap and remove redundant dependencies. When removing redundant dependencies: use the removeUnImportantDependency function to traverse the dependency node list of the current module and determine whether a dependency node can be indirectly dependent on other dependency nodes. If so, remove the dependency node from the dependency list.
[0037] Generate .dot file: Generate a .dot file in graph TD syntax, save the dependency relationship in the form of a graph to the project.dot file, or generate a .dot file in digraph syntax, save the dependency relationship in the form of a directed graph, and save it to the project_digraph.dot file,
[0038] Generate PNG image: Use Graphviz tool to convert .dot file to PNG image file,
[0039] Output the path of the .dot file and convert the dot file into a visual graphic through the Mermaid Live Editor service.
[0040] The method of the present invention collects and organizes the dependency relationships by traversing the modules and dependencies of the Android project in a breadth-first manner, and generates a .dot file. Users can use these .dot files to view and analyze the dependency structure of the project in the tool to help understand the relationship between the modules.
[0041] Example 2
[0042] The present invention also provides a visualization device for Android dependency relationships, including a Gradle task management module,
[0043] The Gradle task management module establishes a Gradle task and specifies the format of dependency output for visualizing project dependencies, including:
[0044] Execute the Graph task: initialize the treeMap, create a LinkedHashMap to store all modules and their dependencies,
[0045] Traverse the project structure, starting from the rootProject, and use the queue breadth-first traversal of all subprojects. For each subproject, call the collection function to collect the current module, and traverse all dependencies of the current module, collect dependencies, and add the current module and its dependencies to the dependency node list of the current project.
[0046] Traverse all modules in treeMap and remove redundant dependencies.
[0047] Generate .dot file: Generate a .dot file in graph TD syntax, save the dependency relationship in the form of a graph to the project.dot file, or generate a .dot file in digraph syntax, save the dependency relationship in the form of a directed graph, and save it to the project_digraph.dot file,
[0048] Generate PNG image: Convert .dot files to PNG image files.
[0049] Output the path of the .dot file and convert the dot file into a visual graphic through the Mermaid Live Editor service.
[0050] As the information interaction and execution process between the modules in the above-mentioned device are based on the same concept as the embodiment of the method of the present invention, the specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.
[0051] Similarly, the device of the present invention dynamically queries the relationship between all dependent libraries based on Gradle for visual display, which is convenient for users to better manage various dependent libraries, optimize componentization solutions, and speed up the compilation and construction of Android applications.
[0052] It should be noted that not all steps and modules in the above-mentioned processes and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.
[0053] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.
Claims
1. A method for visualizing Android dependencies, characterized by include: Create a Gradle task to specify the format of dependency output for visualizing project dependencies, including: Execute the Graph task: initialize the treeMap, create a LinkedHashMap to store all modules and their dependencies, Traverse the project structure, starting from the rootProject, and use the queue breadth-first traversal of all subprojects. For each subproject, call the collection function to collect the current module, and traverse all dependencies of the current module, collect dependencies, and add the current module and its dependencies to the dependency node list of the current project. Traverse all modules in treeMap and remove redundant dependencies. Generate .dot file: Generate a .dot file in graph TD syntax, save the dependency relationship in the form of a graph to the project.dot file, or generate a .dot file in digraph syntax, save the dependency relationship in the form of a directed graph, and save it to the project_digraph.dot file, Generate PNG image: Convert .dot files to PNG image files. Output the path of the .dot file and convert the dot file into a visual graphic through the Mermaid Live Editor service.
2. The method for visualizing Android dependencies according to claim 1, characterized in that: The ModuleNode class represents a list of dependent nodes. The ModuleNode class contains two attributes, namely the module name and the dependency relationship of the current module.
3. The method for visualizing Android dependencies according to claim 1, characterized in that When removing redundant dependencies: traverse the dependency node list of the current module and determine whether a dependency node can be indirectly dependent on other dependency nodes. If so, remove the dependency node from the dependency list.
4. The method for visualizing Android dependencies according to claim 1, characterized in that When generating PNG images, use the Graphviz tool to convert the .dot file to a PNG image file.
5. A visualization device for Android dependency relationships, characterized in that Including Gradle task management module, The Gradle task management module establishes a Gradle task and specifies the format of dependency output for visualizing project dependencies, including: Execute the Graph task: initialize the treeMap, create a LinkedHashMap to store all modules and their dependencies, Traverse the project structure, starting from the rootProject, and use the queue breadth-first traversal of all subprojects. For each subproject, call the collection function to collect the current module, and traverse all dependencies of the current module, collect dependencies, and add the current module and its dependencies to the dependency node list of the current project. Traverse all modules in treeMap and remove redundant dependencies. Generate .dot file: Generate a .dot file in graph TD syntax, save the dependency relationship in the form of a graph to the project.dot file, or generate a .dot file in digraph syntax, save the dependency relationship in the form of a directed graph, and save it to the project_digraph.dot file, Generate PNG image: Convert .dot files to PNG image files. Output the path of the .dot file and convert the dot file into a visual graphic through the Mermaid Live Editor service.
6. The device for visualizing Android dependency relationships according to claim 5, characterized in that The Gradle task management module defines the ModuleNode class, which represents a list of dependency nodes. The ModuleNode class contains two properties: the module name and the dependency relationship of the current module.
7. The device for visualizing Android dependency relationships according to claim 5, characterized in that When the Gradle task management module removes redundant dependencies: it traverses the dependency node list of the current module and determines whether a dependency node can be indirectly dependent on other dependency nodes. If so, the dependency node is removed from the dependency list.
8. The device for visualizing Android dependency relationships according to claim 5, characterized in that When the Gradle task management module generates a PNG image, the Graphviz tool is used to convert the .dot file into a PNG image file.
Citation Information
Cited By
Software package dependency relationship and introduction reason analysis tool based on dpkg
CN120541138A
