相关文章推荐
紧张的电梯  ·  js - import和require - ...·  8 月前    · 
打篮球的拐杖  ·  迁移学习 (Transfer ...·  1 年前    · 

1.包冲突

程序使用了CameraX,后来导入了selenium,就出现问题了,错误如下:

Duplicate class com.google.common.util.concurrent.ListenableFuture found in modules guava-25.0-jre.jar (com.google.guava:guava:25.0-jre) and listenablefuture-1.0.jar (com.google.guava:listenablefuture:1.0)
Go to the documentation to learn how to Fix dependency resolution errors.
复制代码

com.google.guava guava listenablefuture 俩模块都引用了 ListenableFuture ,属于依赖包冲突。经过一番折腾,找到了解决方案。 在冲突的 module 内,找到 build.gradle ,在 android{} 内添加 configurations ,如下:

android {
    ......
    configurations {
        all*.exclude group: 'com.google.guava', module: 'listenablefuture'
        all*.exclude group: 'com.google.guava', module: 'guava'
    ......
复制代码

2.新的问题

解决包冲突后,出现了新的BUG,如下:

More than one file was found with OS independent path 'META-INF/versions/9'
复制代码

这是依赖包冲突遗留问题,工程多个jar包引用同一个文件,生成多个 META-INF/versions/9 文件,故提示出错。 解决方法:在依赖包冲突的 module 或者引用了该 module module build.gradle 文件的 android{} 内添加 packagingOptions ,如下:

android{
    ......
    packagingOptions {
        exclude 'META-INF/*'
        exclude 'META-INF/versions/9'
    ......
复制代码

3.顺便记录查看依赖树的方法

Terminal内

gradlew :xxxx:dependencies --configuration compile/implementation
//xxxx代表module名称,不要忽略module名前面的“:”号
//导包若用compile则configuration参数后面用compile,若是implementation则用implementation
//可以查看简单的依赖包
gradlew :xxxx:dependencies
//同上
//可以查看详细的依赖树
复制代码
分类:
Android