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

Android Studio更新应用时出现Duplicate class androidx.annotation.AnimRes错误

解决方案

首先,你当前根目录build.gradle里的classpath配置不需要修改——已经注释掉Kotlin Gradle插件的做法是正确的,因为你只用Java开发,这个配置不会导致重复类问题。

要解决Duplicate class androidx.annotation.AnimRes的错误,核心是处理重复的注解依赖,按以下步骤操作:

  • 定位重复依赖的来源
    在Android Studio的Terminal中执行命令(Windows系统去掉开头的./):

    ./gradlew app:dependencies
    

    在输出结果里搜索annotation-jvm,找到哪个第三方依赖引入了androidx.annotation:annotation-jvm:1.7.0。

  • 排除重复的依赖模块
    在app模块的build.gradle中,找到对应的依赖,添加排除规则。比如如果是com.xxx:some-library:2.0引入了重复依赖,修改为:

    implementation('com.xxx:some-library:2.0') {
        exclude group: 'androidx.annotation', module: 'annotation-jvm'
    }
    
  • 强制统一注解版本(可选)
    如果找不到具体依赖来源,或者排除后仍有问题,可以在app模块的build.gradle的dependencies块上方添加版本强制规则,统一使用高版本注解库:

    configurations.all {
        resolutionStrategy.force 'androidx.annotation:annotation:1.7.0'
    }
    
  • 清理缓存重新构建
    执行命令清理构建缓存:

    ./gradlew clean build
    

    或者通过Android Studio菜单File -> Invalidate Caches...选择Invalidate and Restart,彻底清理缓存后重新构建项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 02:25:07