【问题标题】:Duplicate class android.support.v4.app.NotificationCompat$Action$Extender found in modules classes.jar (com.android.support:support在模块 classes.jar (com.android.support:support
【发布时间】:2025-12-27 04:05:09
【问题描述】:

我收到多行错误,说它有重复的类

重复类

android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat 在模块 classes.jar 中找到 (com.android.support:support-compat:28.0.0) 和 classes.jar (com.android.support:support-v4:24.0.0) 重复类 android.support.v4.app.ActionBarDrawerToggle 在模块中找到 classes.jar (com.android.support:support-core-ui:28.0.0) 和 classes.jar (com.android.support:support-v4:24.0.0) 重复类 转到文档以了解如何修复依赖关系解析 错误。

我的gradle.app 有如下依赖:

dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.google.android.gms:play-services:10.2.4'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

【问题讨论】:

标签: android android-studio gradle


【解决方案1】:

您需要升级版本,您可以通过使用序列 Alt+Enter 来完成:

现在您不需要使用所有 Google Play 服务,只需使用模块、示例:

implementation 'com.google.android.gms:play-services-ads:VERSION'
implementation 'com.google.android.gms:play-services-auth:VERSION'
implementation 'com.google.android.gms:play-services-gcm:VERSION'

但是如果你真的需要使用'com.google.android.gms:play-services:VERSION',为了避免重复的类在你的app/build.gradle文件中使用这个配置:

implementation ('com.google.android.gms:play-services:10.2.4') {
    exclude group: "com.android.support", module: "support-v4"
}

【讨论】:

    【解决方案2】:

    感谢 Jorgesys 的上述回答是正确的,但我迁移到 androidx 解决了我的问题

    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    

    【讨论】:

      【解决方案3】:

      // 将此属性粘贴到 gradle.properties 中

      android.useAndroidX=true

      android.enableJetifier=true

      1. First Property 将使用适当的 androidx 库,而不是使用旧的支持库。

      2. 第二个会将所有第三方库迁移到 androidx 库。

      【讨论】: