如何在 gradle build for android studio 中修复重复的 类

How to fix duplicate classes in gradle build for android studio

我正在尝试在 build.gradle 中添加广告。但是,它似乎没有用。

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "br.com.alessanderleite.catchtheballgame"
    minSdkVersion 15
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android- 
optimize.txt'), 'proguard-rules.pro'
    }
    }
  }



dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.gms:play-services-ads:9.4.0'
}

错误:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-v4:23.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-v4:23.0.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-v4:23.0.0)

转到文档以了解如何修复依赖项解析错误。

您正在使用

implementation 'com.google.android.gms:play-services-ads:9.4.0'

此版本使用了支持库,您不能同时使用 androidx 和支持库。

使用 update version 的广告迁移到 androidx。

implementation 'com.google.android.gms:play-services-ads:18.2.0'