Making: coolmaye

This article is an intuitive solution to project dependency conflicts

Depend on the type

Implementation: Dependency mode is only limited to “current module”, advantages increase compilation speed, external hidden call interface

API: The most common dependency method involved in compiling and packaging an app

CompileOnly: participate in compilation but not final packaging. You can avoid conflicts by relying on the most common libraries in your own Modules

RuntimeOnly: does not participate at compile time, hides all interfaces externally, and only takes part in the final packaging

Some of the following methods are referenced for dependency conflict resolution

Rely on conflict resolution

There are two steps here

“Gradlew” is not an internal or external command, and it is not an executable program. Gradlew and gradlew. Bat files from the root directory of other projects.

2. Add the following code to the build.gradle root node of the Module

    resolutionStrategy {
        failOnVersionConflict()// Version conflict error}}Copy the code

Then click Sync Now in the upper right corner to synchronize

The conflicting version numbers will pop up in the Messages page, indicating that one of the following libraries is in conflict

At this moment we have [two] ways to deal with it

Direct unification: Specify all version numbers as the current version

configurations.all {
    resolutionStrategy {
        failOnVersionConflict()// Version conflict error
        force 'com. Squareup. Okio: okio: 1.15.0'// Force the version}}Copy the code

// failOnVersionConflict() this method is then repackaged when the wrong class is processed.

Remove the alien method: select okio:1.13.0 and go back to Terminal, press Ctrl+F to search for the dependency in which the library is used. After the search, find the dependency in build.gradle and remove the corresponding package

 implementation ('com. Squareup. Okhttp3: okhttp: 3.9.0'){

        exclude group: 'com.squareup.okio'
 }
Copy the code

Recompile to see that the conflict is resolved

4. Pay attention to

Gradle automatically uses the latest version of the gradle library to eliminate most of these problems. However, some of these problems need to be handled manually.