In the process of project development, we more or less introduce third-party libraries. The more libraries we introduce, the more likely it is to have dependency conflicts between libraries.

Here is the problem I encountered to restore:

When I connected to the customer service system of Ronglian before, there was a flash back when I entered the customer service page after the integration was completed. Let’s review the error message:

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)
Copy the code

We can skip to the place where the error is reported:

The newspaper is wrong meaning: no

into(Landroid/widget/ImageView)
Copy the code

< div style = “max-width: 100%; clear: both; clear: both; Before the dependency was added, Glide was also used to load pictures in the project. Is it possible that Glide in the project conflicts with Glide in the joint Demo?

Into method where error was reported:

It can be seen that the Version of Glide used by the Union Demo is 3.7.0.

Let’s look at the version Glide used in the project:

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

At this time I thought of a really large probability is the Glide version of the two conflict.

Sure enough, the Glide version in the ronglian Demo was changed to 4.5.0, and after the compilation and operation entered the customer service interface, no error was reported, perfect solution.

This is the problem of library conflict that I met before. The error message of this problem can be identified as the problem of Glide library dependence. If there are other error messages that are not so significant, it will be a headache.

Encounter this problem at that time, the way I didn’t use to see depend on the tree, but directly to the source code, because I don’t know can do that at the time, fortunately, locate the problem soon, so when we upgrade the third-party libraries or the introduction of a new third party libraries, library and library dependency between conflict, we need to know and rely on the tree every third party dependent libraries, Knowing the dependency tree makes it clear where the conflict is.

Here are a few ways to view a dependency tree:

Solution 1: View the Gradle Task tool

1. Click “Gradle” in the upper right corner of the Android Studio panel, as shown in the picture:

2. Double-click dependencise according to the directory as shown in the figure, the Run console will output the print, as shown in the figure:

3. Print as shown in the figure:

Plan 2: Use Gradle View plug-in

1. Shortcut Ctrl+Alt+ S, open Settings, and click the Plugins button

2. Search for Gradle View and install it. Then restart Android Studio

3. On the menu bar, go to View -> Tool Windows -> Gradle View and wait for a while.

As shown in the figure:

Solution 3: Terminal console view

Use this command in Android Studio Terminal on Windows:

Gradlew: app: dependencies (" app "for themoduleThe name)Copy the code

Use the following command in MacOS:

. / gradlew: app: dependencies (" app "for themoduleThe name)Copy the code

This command will gradle perform every step of printed, including releaseUnitTestRuntimeClasspath, releaseUnitTestCompileClasspath, releaseRuntimeClasspath, ReleaseCompileClasspath lintClassPath, debugUnitTestRuntimeClasspath and so on.

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

 ./gradlew :app:dependencies --configuration compile
Copy the code

On Windows, you don’t need to start with./, just use gradlew.

Execute the Dependencies task under the APP module; Additionally configure compile, the dependencies in the compile environment.

By looking at the dependency tree, we can see which dependencies conflict with each other. For example, a framework’s support package conflicts with each other.

{
   exclude group:'com.android.support'
}
Copy the code

This will remove the support package for the framework.