You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Android Studio后:app:checkDebugDuplicateClasses任务失败求助

Glide类重复导致Android构建失败(Task :app:checkDebugDuplicateClasses FAILED)

环境配置

  • 已更新Android Studio
  • Gradle相关配置:
    项目级build.gradle中的classpath:
    classpath 'com.android.tools.build:gradle:7.3.1'
    
    gradle-wrapper.properties中的distributionUrl:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
    

构建错误信息

Task :app:checkDebugDuplicateClasses FAILED

> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
   > Duplicate class com.bumptech.glide.GeneratedAppGlideModule found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.GenericTransitionOptions found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Glide found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.GlideBuilder found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.GlideBuilder$1 found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.GlideContext found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.ListPreloader found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.ListPreloader$PreloadModelProvider found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.ListPreloader$PreloadSizeProvider found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.ListPreloader$PreloadTarget found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.ListPreloader$PreloadTargetQueue found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.MemoryCategory found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.ModelTypes found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Priority found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Registry found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Registry$MissingComponentException found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Registry$NoImageHeaderParserException found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Registry$NoModelLoaderAvailableException found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Registry$NoResultEncoderAvailableException found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.Registry$NoSourceEncoderAvailableException found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestBuilder found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestBuilder$1 found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestBuilder$2 found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestManager found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestManager$1 found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestManager$2 found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestManager$ClearTarget found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.RequestManager$RequestManagerConnectivityListener found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.TransitionOptions found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.DataSource found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.DecodeFormat found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.EncodeStrategy found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.Encoder found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.HttpException found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.ImageHeaderParser found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.ImageHeaderParser$ImageType found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.ImageHeaderParserUtils found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.Key found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.MultiTransformation found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.Option found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.Option$1 found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.Option$CacheKeyUpdater found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.Options found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.ResourceDecoder found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.ResourceEncoder found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)
     Duplicate class com.bumptech.glide.load.Transformation found in modules glide-4.4.0 (com.github.bumptech.glide:glide:4.4.0) and glide-4.4.0-runtime (com.github.bumptech.glide:glide:4.4.0)

解决方案

1. 检查并移除重复的Glide依赖

打开app/build.gradle,查看dependencies块,确认是否同时引入了com.github.bumptech.glide:glide:4.4.0和com.github.bumptech.glide:glide:4.4.0-runtime。如果是,直接删除runtime版本的依赖——主Glide依赖已经包含runtime模块的所有内容,重复引入会导致类冲突。

2. 排查间接依赖导致的重复

如果手动引入的依赖没有重复,大概率是第三方库间接引入了Glide的runtime模块。执行以下命令查看完整依赖树:

# macOS/Linux
./gradlew app:dependencies

# Windows
gradlew.bat app:dependencies

在输出中查找com.github.bumptech.glide相关的依赖,找到重复引入的来源,然后在对应的依赖中排除runtime模块:

// 如果是主Glide依赖被重复引入
implementation ('com.github.bumptech.glide:glide:4.4.0') {
    exclude module: 'glide-runtime'
}

// 如果是第三方库带的重复依赖
implementation ('第三方库的完整坐标') {
    exclude group: 'com.github.bumptech.glide', module: 'glide-runtime'
}

3. 清理构建缓存并重新构建

  • 点击Android Studio菜单栏的File -> Invalidate Caches... -> Invalidate and Restart,清理IDE缓存并重启
  • 或者在终端执行命令清理项目构建缓存:
# macOS/Linux
./gradlew clean build

# Windows
gradlew.bat clean build

4. 升级Glide版本(可选)

Glide 4.4.0属于较旧版本,可能存在依赖结构设计的问题。升级到稳定的新版本(如4.16.0)可以避免这类问题,同时记得同步升级注解处理器:

implementation 'com.github.bumptech.glide:glide:4.16.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'

内容的提问来源于stack exchange,提问作者Niklas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 23:16:24