Android checks the dependency information of the project and which version of the component is the correct posture in the dependency library

Recently, I have been sorting out the dependency information in the project, and there are many ways to view the dependency information. Here I will only talk about the methods that I personally think are more useful:

Output all dependency information of the specified module to the specified file

Format:

./gradlew :模块名:dependencies > 文件名.txt

Example:

./gradlew :app:dependencies > deps.txt

After the task is executed, a txt file named by you will be generated, which contains a lot of content, and lists all the dependencies of the environment for you. There are a lot of them. Generally, we only need to care about the following

  • debugRuntimeClasspath debug runtime dependencies
  • debugCompileClasspath debug compile-time dependencies
  • releaseRuntimeClasspath release runtime dependencies
  • releaseCompileClasspath release compile-time dependencies

Then go to view the corresponding dependency information.

View the dependency information of the specified environment

There is too much interference information output in the above way, we can specify to output only the dependencies of a certain environment

For example:

./gradlew app:dependencies > deps.txt  --configuration releaseCompileClasspath       

At this time, only the dependencies of releaseCompileClasspath will be output to txt.

But if you configure it productFlavors, if you execute the above command directly, an error will be reported, indicating that it cannot findreleaseCompileClasspath

Configuration 'releaseCompileClasspath' not found in configuration container.

Example:
The productFlavors error message is configured
insert image description here
:
insert image description here

The reason is also relatively simple, because the environment name has changed, releaseCompileClasspathjust change it to one with a productFlavors prefix, as prdReleaseCompileClasspath
in the example:
insert image description here

Check which library brings in a certain version of the dependency

Another requirement is that I want to see which library brings in the dependency of a certain version
. It must be that a certain component I depend on internally depends on version 1.7.10, resulting in the final actual dependent version not being 1.6.21, but 1.7.10. At this time, I want to confirm which component internally depends on 1.7.10 version of kt.

There are two ways

method one

First of all, the first step is to pull out the overall dependencies. Note that the dependency information of the runtime environment needs to be used here.
Then search directly for keywords such askotlin:kotlin-stdlib:1.7.10

insert image description here

After finding it, go up to find out who his parent is, just judge the parent according to the blue ±–
insert image description here

found to be androidx.appcompat:appcompat:1.5.1internally dependentorg.jetbrains.kotlin:kotlin-stdlib:1.7.10

Then go to the mvnrepository warehouse to search for the specified library to confirm .
insert image description here

It can be seen androidx.appcompat:appcompat:1.5.1that the 1.7.10 version of kotlin-stdlib is indeed dependent on

way two

Use the command to print out which libraries the dependencies of the specified version exist in

Format

 ./gradlew 模块名:dependencyInsight > 文件名.txt --configuration 环境 --dependency 要查找的依赖组件名称

Example:

 ./gradlew app:dependencyInsight > kotlin.txt --configuration prdReleaseRuntimeClasspath --dependency kotlin:kotlin-stdlib

The result is as follows, and it can also be found that it is androidx.appcompat:appcompat:1.5.1dependent onkotlin-stdlib:1.7.10
insert image description here


build scan

Execute ./gradlew build --scanthe command and enter yes according to the prompt

insert image description here
The construction information of the project will be generated as a web link.
insert image description here
Clicking on the link will allow you to enter your email address for the first time, and an email will be sent to you later

insert image description here

Click the link in the mailbox to view very detailed build information. Here we only look at the dependent modules
insert image description here
and the internal dependencies of the specified dependent library.
insert image description here

Well, that’s all. Basically, these methods can solve the problems of obtaining dependencies and versions in most scenarios. I hope they can help you.


If you think this article is helpful to you, please give it a thumbs up. It can help more developers. If there are any mistakes in the article, please correct me. For reprinting, please indicate that you are reposting from Yu Zhiqiang’s blog, thank you !

Guess you like

Origin blog.csdn.net/yuzhiqiang_1993/article/details/127846846