Article from: blog.csdn.net/yuzhiqiang_…
Because this problem is still very common, but the time is likely to be forgotten. So publish it so you can look at it later.
All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes
This error is most likely to occur when adding third-party libraries using Android Studio.
The com.android.support package version should be the same, but the com.android.support package version of our new project may be higher. The com.android.support of some third-party libraries may not have updated the support library in a timely manner.
Resolution (the same applies to other dependency conflicts.)
- Change the version number of com.android.support in your own project to match the version number of the library you rely on, but not when there are several versions of com.android.support in the library you rely on. (Not recommended)
- When relying on third-party libraries, eliminate dependencies on the com.android.support package, so that your project can rely on any version, but this method requires you to find out which inventory conflicts first
- Forcing changes to conflicting dependency library versions using Groovy scripts (recommended)
Method of exclusion dependence
Let’s look at the second method first
Run the gradlew -q app:dependencies command to display the libraries in your app
Select * from arouter; select * from arouter; select * from arouter; select * from arouter;
Exclude group: exclude any API that contains com.android.support. Exclude group: exclude any API that contains com.android.support. Exclude group: exclude any API that contains com.android.support
Such as:
API ("com.afollestad.material- Dialogs :core:0.9.5.0") {exclude group: 'com.android.support'}Copy the code
Module: deletes specified modules from the group.
API ("com.afollestad.material- Dialogs :core:0.9.5.0") {exclude group: 'com.android.support', module: 'support-v13' exclude group: 'com.android.support', module: 'support-vector-drawable' }Copy the code
We also recommend providing com.android.support to compileOnly if you want to create your library for others. This only works at compile time and does not participate in packaging. To avoid inconvenience to users.
Ex. :
Provided 'com. Android. Support: appcompat - v7:26.1.0' provided 'com. Android. Support: design: 26.1.0' provided 'com. Android. Support: support vector - drawable: 26.1.0'Copy the code
Resolve conflicts by modifying version numbers using the Grovvy script
Add the following code to the build.gradle file of the conflicting Module by iterating through all dependencies and changing the version number of the specified library
Requested. Group == ‘com.android.support’ com.android.support indicates the dependent library to be modified
UseVersion ‘28.0.0’ 28.0.0 indicates the version number to be modified
configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (! Requested. Name. StartsWith (" multidex ")) {the useVersion '28.0.0'}}}}Copy the code
Again, this article belongs to reprint, author information is as follows.
CSDN: blog.csdn.net/yuzhiqiang_… Copyright notice: This article is the blogger’s original article, reprint please attach the blog link!