The background,

In A project, different libraries (libraries A and B) are referenced. When different libraries depend on different versions of A library at the same time (for example, A depends on version 1.1 of C and B depends on version 2.2 of C), dependency conflicts occur.

Second, the steps of problem solving

Viewing the dependency tree

Run the following Tasks in Android Studio to generate dependencies and see which libraries introduced the conflict (that is, find libraries A and B).

Eliminate dependence on

Use exclude group: ‘group_name, module:’ module_name ‘

// Remove all com.android.support dependencies from the rxpermissions dependency, Avoid conflict and our own implementation 'com. Making. Tbruyelle: rxpermissions: 0.10.2', {exclude group: 'com. Android. Support'}Copy the code

Pay attention to: The red box in the figure below indicates that the dependent version has been promoted from 1.0.0 to 1.1.0. If you exclude a group or module from the 1.0.0 library, the exclusion will not be valid when the library version is upgraded.

Using mandatory versions

Conflicting libraries contain multiple versions, so you can use mandatory versions directly. Configurations. All {} = resolutionStrategy.force = resolutionStrategy.force = resolutionStrategy.force = resolutionStrategy.force = resolutionStrategy.force = resolutionStrategy.force = resolutionStrategy.force = resolutionStrategy.force As shown below, the com.android.tools:sdklib package is forcibly dependent on 30.0.0: