Resolve the problem of repeated references to third-party libraries in Android

If a new third-party library is introduced into the app, and another library that has already been introduced is introduced into this new library, which results in repeated references, the compilation will report an error. How to solve it? The method is to use exclude to exclude duplicate libraries.
Example:
Suppose the newly introduced third-party library is: com.xiboliya.mylib:nettools:1.0.5, and the repeatedly introduced library is: com.google.code.gson:gson.
The way to introduce the library in the build.gradle file before is:

dependencies {
  api 'com.xiboliya.mylib:nettools:1.0.5'
}

Now it needs to be changed to this:

dependencies {
  api ('com.xiboliya.mylib:nettools:1.0.5') {
      exclude group:'com.google.code.gson', module: 'gson'
  }
}

After modifying the build.gradle file, re-Sync and compile again.

Guess you like

Origin blog.csdn.net/chenzhengfeng/article/details/104921529