如何修复“重复的类 com.google.android.gms.common.api.internal.zza"错误?
我已将 Android Studio 更新到 3.4 和 Admob
库编译 'com.google.android.gms:play-services-ads:12.0.1'
到实施 'com.google.android.gms:play-services-ads:17.2.0'
I have updated Android Studio to 3.4 and Admob
library from
complie 'com.google.android.gms:play-services-ads:12.0.1'
to
implementation 'com.google.android.gms:play-services-ads:17.2.0'
之后,当我尝试运行应用程序时出现重复类错误.
After that I got duplicate class error when I tried to run app.
我得到了错误
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.
顶级等级
// 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
}
```
应用程序的gradle
App's gradle
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'
}```
推荐答案
请从这个 link,并相应地替换您的 gradle 文件中的正确版本.
Please look up the latest google's play service libraries from this link, and replace the correct version in your gradle file accordingly.
在应用程序的build.gradle"文件中,将以下内容与android {...}"一起添加
In the app's "build.gradle" file, add the following along with "android {...}"
configurations.all {
resolutionStrategy {
force 'com.google.android.gms:play-services-basement:17.1.0'
}
}
当时,最新的 google play services basement library 版本是 17.1.0.
At the time, the lastest google play services basement library version is 17.1.0.
希望这会有所帮助.
相关文章