解决 Android 开发过程中 出现 Duplicate class(包冲突)

1、现在大部分的项目都是支持 Androidx 的,所以出现 Duplicate 的时候

先把 gradle.properties 文件中添加参数,支持使用AndroidX

android.useAndroidX=true
android.enableJetifier=true

2、有些 *.jar/*.aar 不支持 AndroidX 的时候,将上面的禁用

然后再排除 AndroidX 的引用
 

configurations{
    all*.exclude group: 'androidx.*.*'
    ...
}

有很多,搜索一下 androidx 就能找到

3、排除了Androidx 的冲突后,包还有冲突 

类似 v4. com 这种

1、先看看冲突的是哪个包,在Android studio  Project 中的 External Libraries 中

 这种基本都是在 app->build.gradle 文件中 implementation 导入进去的

所以要排除导入包中的 某个冲突的模块
 

    implementation ('com.android.support:multidex:1.0.1') {
        exclude group: 'com.android.support'
        exclude module: 'appcompat-v7'
    }

要是冲突的包比较多只能先删除本地的 jar 文件了。要是舍不得那就一个个去排除。

猜你喜欢

转载自blog.csdn.net/huanghuipost/article/details/128267706