Duplicate class android.support.v4.app.NotificationCompat$Action$Extender found in modules classes.jar (com.android.support:support) 在模块classes.jar (com.android.support:support) 中发现重复的类android.support.v4.app.NotificationCompat$Action$Extender。

3
我收到了多行错误,这些错误说它有重复的类。在模块classes.jar(com.android.support:support-compat:28.0.0)和classes.jar(com.android.support:support-v4:24.0.0)中发现了重复的类android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat。类android.support.v4.app.ActionBarDrawerToggle也发生了重复,分别在modules 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'

}

可能是重复的问题:如何查找导致类重复的依赖项? - Zoe stands with Ukraine
3个回答

1

您需要升级版本,可以通过使用序列Alt+Enter在行上进行此操作:

enter image description here

现在你不需要使用所有的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"
}

0

// 将这些属性粘贴到 gradle.properties 中

android.useAndroidX=true

android.enableJetifier=true

  1. 首先,第一个属性将使用适当的androidx库,而不是使用旧的support库。

  2. 其次,将所有第三方库迁移到androidx库。


0
感谢上面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'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接