如何解决“重复的类com.google.android.gms.common.api.internal.zza”错误?

时间:2019-05-11 12:18:48

标签: java android admob

我已将Android Studio更新为3.4和Admobcomplie 'com.google.android.gms:play-services-ads:12.0.1'  至 implementation 'com.google.android.gms:play-services-ads:17.2.0'

在那之后,当我尝试运行应用程序时出现重复的类错误。

我遇到错误

Duplicate class com.google.android.gms.common.api.internal.zza found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.api.internal.zzb found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.api.internal.zzc found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.api.internal.zzd found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.api.zza found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.api.zzb found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.internal.zzb found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.internal.zzr found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.internal.zzs found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)
Duplicate class com.google.android.gms.common.zze found in modules classes.jar (com.google.android.gms:play-services-base:12.0.1) and classes.jar (com.google.android.gms:play-services-basement:16.0.1)

Go to the documentation to learn how to Fix dependency resolution errors.

顶级gradle


    // Top-level build file where you can add configuration options common to all sub-projects/modules.

    buildscript {
        repositories {
            google()
            jcenter()
            maven { url 'https://maven.fabric.io/public' }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.4.0'
            classpath 'com.google.gms:google-services:4.2.0'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
            classpath 'io.fabric.tools:gradle:1.28.1'
        }
    }

    allprojects {
        repositories {
            google()
            jcenter()
        }
    }

    task clean(type: Delete) {
        delete rootProject.buildDir
    }

    ```

应用程序的摇篮

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.27.1'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 27
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "xx.xxx"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 23
        versionName "1.23"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        manifestPlaceholders = [onesignal_app_id: "xxxx-xxx-xxx-xxx",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "REMOTE"]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:customtabs:27.1.1'
   // implementation 'com.google.android.gms:play-services-base:16.1.0'
    //compile 'com.google.android.gms:play-services-gcm:12.0.1'
    implementation 'com.google.android.gms:play-services-ads:17.2.0'
    //compile 'com.google.android.gms:play-services-basement:16.0.1'
    //compile 'com.google.android.gms:play-services-measurement-sdk-api:17.2.0'

    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.onesignal:OneSignal:3.10.8'

    implementation 'com.android.support:multidex:1.0.3'
    // retrofit, gson
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'

    implementation 'org.droidparts:droidparts:3.2.5'
    implementation 'org.jsoup:jsoup:1.11.3'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.9@aar') {
        transitive = true;
    }
    testImplementation 'junit:junit:4.12'
}```

1 个答案:

答案 0 :(得分:0)

请从此link查找最新的Google Play服务库,并相应地在gradle文件中替换正确的版本。

在应用程序的“ build.gradle”文件中,添加以下内容以及“ android {...}”

configurations.all {
    resolutionStrategy {
        force 'com.google.android.gms:play-services-basement:17.1.0'
    }
}

当时,最新的Google Play服务地下室库版本为17.1.0。

希望这会有所帮助。