android 解决 jar包重复问题:IDE报错发现重复类

引入三方SDK出现:Duplicate class com.xxx.xxx found in modules

例如:Duplicate class org.apache.commons.codec.BinaryDecoder found in modules jetified-commons-codec-1.5.jar (commons-codec:commons-codec:1.5) and jetified-org.apache.http.legacy.jar (org.apache.http.legacy.jar)

翻译:在jetified-commons-codec-1.5.jar(commons codec:commons codec:1.5)和jetified-org.apache.http.legacy.jar(org.apache.http.legacy.jar)模块中找到重复的org.apache.commons.codec.BinaryDecoder类

解决:

    一、定位。

Android studio - Navigate-Class-搜索重复的类

二、点开重复的jar,处理

    1、如jar无用可直接删除。

    2、用 解决,就是去掉 你不需要的类 如:

  implementation ('com.squareup.retrofit2:converter-gson:2.3.0'){

         exclude group:'com.google.code.gson'

         exclude group: 'com.squareup.okhttp3'

       }

或者 

    exclude module:'glide'

三、如果依然无效,则改变三方库内的jar的引入方式。

        这时候需要将implementation fileTree(dir:'libs',include: ['*.jar']) 去掉。

        单独引用jar,将冲突改为compileOnly!!!!


你可能感兴趣的:(android 解决 jar包重复问题:IDE报错发现重复类)