Android构建失败:重复类依赖冲突问题求助
解决Android构建依赖冲突问题
你的构建任务:app:checkDebugDuplicateClasses失败,核心原因是依赖包中存在重复类,具体涉及两组冲突:
- Fresco的
imagepipeline-base:2.5.0和stetho:2.0.0重复包含CountingMemoryCacheInspector相关类 - Guava的
guava:26.0-android和listenablefuture:1.0重复包含ListenableFuture类
以下是针对性的解决方案:
1. 修复Fresco模块重复类冲突
在app模块的build.gradle(或build.gradle.kts)中,给stetho依赖排除掉重复的imagepipeline-base模块:
// Groovy 语法 implementation('com.facebook.fresco:stetho:2.0.0') { exclude group: 'com.facebook.fresco', module: 'imagepipeline-base' }
// Kotlin DSL 语法 implementation("com.facebook.fresco:stetho:2.0.0") { exclude(group = "com.facebook.fresco", module = "imagepipeline-base") }
2. 修复Guava模块重复类冲突
Guava 26.0-android版本已经内置了ListenableFuture类,无需单独引入listenablefuture包,可通过两种方式解决:
方式一:排除特定依赖中的listenablefuture
找到引入com.google.guava:listenablefuture:1.0的第三方依赖,给该依赖添加排除规则:
// Groovy 示例 implementation('第三方库坐标') { exclude group: 'com.google.guava', module: 'listenablefuture' }
// Kotlin DSL 示例 implementation("第三方库坐标") { exclude(group = "com.google.guava", module = "listenablefuture") }
方式二:全局强制统一版本
在项目根目录的build.gradle(或build.gradle.kts)中添加全局依赖规则,使用Guava官方提供的空jar来避免冲突:
// Groovy 语法 allprojects { configurations.all { resolutionStrategy { force 'com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava' } } }
// Kotlin DSL 语法 allprojects { configurations.all { resolutionStrategy { force("com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava") } } }
3. 验证修复结果
执行清理并重新构建命令:
# macOS/Linux ./gradlew clean build # Windows gradlew clean build
内容的提问来源于stack exchange,提问作者homayoun Alipour
相关产品推荐
相关产品推荐

