Android Studio view third-party library dependency tree

In the Android development process, we will more or less introduce third-party libraries. The more libraries we introduce, the easier it is to generate dependency conflicts between libraries. So today we will learn about Android Studio and view the third-party library dependency tree.

Let's restore the problem I encountered:

When connecting to the Renronglian customer service system before, a flashback occurred when entering the customer service page after the integration was completed. Let’s review the error message:

122.jpg

Let's take a look at the error code:

java.lang.NoSuchMethodError: No virtual method into (Landroid/widget/ImageView;)Lcom/bumptech/glide/request/target/Target; in class Lcom/a/a/i; or its super classes (declaration of 'com.a.a.i' appears in/data/app/com.sami91sami.h5-1/base.apk)

We can jump to the place where the error is reported according to the error:

133.jpg

The meaning of the error is: no

into(Landroid/widget/ImageView)

method, the code can be compiled and passed, indicating that dependencies must be added to the project, so why is this error reported? Before adding dependencies, Glide is also used in the project to load images. Could it be that there is a conflict between Glide in the project and Glide in Ronglian Demo?

We can click into the source code according to the into method where the error is reported:

144.jpg

You can see that the Glide version used by Ronglian Demo is 3.7.0.

Let's take a look at the version used by Glide in the project:

155.jpg

You can see that the Glide version used in the project is 4.5.0.

At this time, I thought that there is a high probability that there is a conflict between the Glide versions of the two.

Sure enough, after changing the Glide version in Ronglian Demo to 4.5.0, after compiling and running and entering the customer service interface, no error was reported, and it was perfectly resolved.

This is the problem of library conflicts I encountered before. This problem has an error message that can be located as a problem of Glide library dependency. If other error messages are not so obvious, it will be a headache.

When I encountered this problem at the time, I did not use the method of viewing the dependency tree, but directly checked the source code, because I didn’t know that I could do this at the time. Fortunately, I quickly located the problem, so when we upgraded the first When a three-party library or a new third-party library is introduced, there is a dependency conflict between the library and the library. We need to know the dependency tree of each third-party dependency library. Knowing the dependency tree will make it clear where the conflict is.

Here are a few ways to view the dependency tree:

Solution 1: Gradle task tool view

1. Click "Gradle" in the upper right corner of the Android studio panel, as shown in the figure:

1639041944906-gzb.png

2. Find the dependency and double-click it according to the directory shown in the figure, and it will output and print on the Run console, as shown in the figure:

222.png

3. Print as shown in the figure:

333.png

Solution 2: Use the Gradle View plugin

1. Shortcut key Ctrl+Alt+s, open settings, and then click the button Plugins

444.png

2. Search for Gradle View, then install it, and restart Android Studio. This is a screenshot after I have successfully installed it

555.png

3. Click View -> Tool Windows -> Gradle View on the menu bar, and wait for a while to view it.

666.png

as the picture shows:

777.png

Solution 3: Terminal console view

Use this command in Android studio Terminal on windows:

gradlew :app:dependencies(“app”为module名称)

On MacOS use the following command:

./gradlew :app:dependencies(“app”为module名称)

This command will print out all the steps executed by gradle, including releaseUnitTestRuntimeClasspath, releaseUnitTestCompileClasspath, releaseRuntimeClasspath, releaseCompileClasspath, lintClassPath, debugUnitTestRuntimeClasspath, etc.

Then, we can configure the configuration parameter to only view one of the dependency trees.

 ./gradlew :app:dependencies --configuration compile

Under the Windows system, there is no need to use the beginning of ./, just use gradlew directly.

Execute the dependencies task under the app module; additionally configure compile, dependencies in the compilation environment.

888.png

By looking at the dependency tree, we can see which dependencies have conflicts, such as the support package conflict of a certain framework, as long as the conflicting dependencies are found in the gradle file of the moudle, enclose them in brackets and add:

{
   exclude group:'com.android.support'
}

This will remove the support package of the framework.

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/131086163