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

Android项目报错Program type already present: com.android.volley.Cache$Entry如何解决?

解决Android项目中Program type already present: com.android.volley.Cache$Entry错误

嘿,这个问题我之前踩过坑!错误提示的Program type already present本质就是依赖重复冲突——同一个类在编译阶段被多次引入,编译器不知道该用哪一个,就抛出了这个错误。

问题根源分析

看你的依赖配置,问题出在这两个依赖上:

  • com.github.bumptech.glide:volley-integration:1.4.0:这个Glide的Volley集成库本身已经内置了Volley的依赖
  • com.android.volley:volley:1.0.0:你又单独添加了一份Volley的官方依赖

这就导致Volley的com.android.volley.Cache$Entry类被两次引入,触发了冲突。

两种解决方案

方案一:移除重复的Volley依赖(推荐)

直接删掉单独添加的Volley依赖,只用Glide集成库自带的版本就行。修改后的依赖配置如下:

dependencies { 
    implementation fileTree(dir: 'libs', include: ['*.jar']) 
    implementation 'com.android.support:appcompat-v7:26.1.0' 
    implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
    implementation 'com.android.support:design:26.1.0' 
    implementation 'com.android.support:support-v4:26.1.0' 
    implementation 'com.squareup.retrofit2:retrofit:2.1.0' 
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0' 
    implementation 'com.jakewharton:butterknife:8.4.0' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.1' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
    implementation 'com.github.bumptech.glide:volley-integration:1.4.0' 
    // 删掉下面这行重复的Volley依赖
    // implementation 'com.android.volley:volley:1.0.0' 
    implementation 'com.android.support:cardview-v7:26.1.0' 
    implementation 'com.android.support:recyclerview-v7:26.1.0' 
}

方案二:排除集成库中的Volley,使用指定版本

如果你需要使用特定版本的Volley,可以通过exclude移除集成库中的内置Volley,再保留自己指定的版本:

dependencies { 
    // ...其他依赖不变
    implementation ('com.github.bumptech.glide:volley-integration:1.4.0') {
        // 排除集成库中的Volley依赖
        exclude group: 'com.android.volley', module: 'volley'
    }
    implementation 'com.android.volley:volley:1.0.0' 
    // ...其他依赖不变
}

验证方法

修改完依赖后,点击Android Studio工具栏中的Sync Project with Gradle Files按钮同步项目,然后重新编译,这个错误应该就消失了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:12:40