Demand background

At present, android apps with a certain scale may rely on dozens or even hundreds of AArs. There are complex dependencies among these AArs. Sometimes we need to know exactly what is the version number of each AARS used by the APK constructed at that time if we want to check some online errors. Which libraries do these AArs depend on? What are the version numbers of these libraries?

We expect to output a file on THE CI when the APK build is complete. The output file contains the version numbers of each dependent library and the version numbers of the libraries that these dependent libraries depend on

Difficulties in plug-in implementation

What we can confirm is that there should be at least one task to fulfill this requirement, and that task should get the version numbers of all aArs that our application depends on. And the version numbers of the dependent libraries for those AArs themselves. Write the information into a file when you get it.

The first question is where do we schedule this task to be executed? After going through the agP compilation process, we found the best time to execute our task before preBuild it.

Val task = project.tasks. Create ("findDependenciesTask", "findDependenciesTask") FindDependenciesTask::class.java) project.tasks.findByName("preBuild")? .dependsOn(task)Copy the code

The second and most critical question is how do we get information about these dependency libraries

Project. The configurations. The forEach {/ / in general We only build the implementation of the release of the release is usually the debug we debug scenario if don't have to pay attention to the information (it.name.toLowerCase() == "defaultreleaseruntimeclasspath") { it.incoming.resolutionResult.root.dependencies.forEach { It2 -> // Here you can get all the information about the dependent libraries, but we usually only focus on our own libraries, DependencyResultInfo (it2.toString().startswith ("com.xiaomi. Space ")) {dependencyResultInfo (it2.toString().startswith ("com.xiaomi += "$it2 \n" += "$it2 \n" += "$it2 \n" += "$it2 \n" = "$it2 \n < span style = "max-width: 100%; clear: both; min-height: 1em; But here we can no longer print the third layer in order to simple the dependencies of the / / you need to deal with it2. Selected. Dependencies. ForEach {it3 - > dependencyResultInfo + = "-----------------$it3 \n" } } dependencyResultInfo += "----------------------------------------- \n" } } } }Copy the code

Once we get the above information we just write it into a file. Note that the location of the file is the same as the location exposed on your CI. Otherwise, the product of CI construction would not have your file oh

See the effect

Com. Xiaomi. Space. Feedback: xiaomispace_feedback: 4.6.2.0 - the SNAPSHOT -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- com. Xiaomi. Space. The core: xiaomispace_core: 4.6.2.0 - the SNAPSHOT - > Com. Xiaomi. Space. The core: xiaomispace_core: 4.7.999.2 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Com. Xiaomi. Space. Ewarranty: xiaomispace_ewarranty: 4.6.2.0 - the SNAPSHOT -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- com. Xiaomi. Space. The core: xiaomispace_core: 4.6.2.0 - the SNAPSHOT - > Com. Xiaomi. Space. The core: xiaomispace_core: 4.7.999.2 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - Com. Xiaomi. Space. Weex: xiaomispace_weexcore: 4.6.2.1 - the SNAPSHOT -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- com. Xiaomi. Space. The core: xiaomispace_core: 4.6.2.0 - the SNAPSHOT - > Com. Xiaomi. Space. The core: xiaomispace_core: 4.7.999.2 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- com. Alibaba: fastjson: 1.2.58 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - org. Apache. Weex: sdk_legacy: 0.28.0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- com. Android. Support: support - v4:28.0.0 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - com. Xiaomi. Space. Hardwaredetect: xiaomispace_hardwaredetect: 4.5.0.0 - the SNAPSHOT -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- com. Xiaomi. Space. The core: xiaomispace_core: 4.5.0.0 - the SNAPSHOT - > Com. Xiaomi. Space. The core: xiaomispace_core: 4.7.999.2Copy the code