重复条目错误: com/google/android/gms/location/places/zzj.class。

11

当我尝试运行我的项目时,出现了以下错误:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/location/places/zzj.class

这是我正在使用的 build.gradle 文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'io.realm:realm-gradle-plugin:0.89.1'
    }
}
apply plugin: "com.android.library"
apply plugin: "realm-android"

repositories {
    jcenter()
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
    }

    buildTypes {
        debug {
            minifyEnabled false
        }
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:23.1.1"
    compile "com.android.support:cardview-v7:23.1.1"
    compile "com.android.support:recyclerview-v7:23.1.1"
    compile "com.android.support:design:23.1.1"
    compile "com.squareup.okhttp3:okhttp:3.1.2"
    compile ('com.facebook.android:facebook-android-sdk:4.9.0')
        { exclude group: 'com.android.support' }
    compile ('com.googlecode.libphonenumber:libphonenumber:7.2.2')
        { exclude group: 'com.android.support' }
    compile "com.pubnub:pubnub-android:3.7.6"
    compile "com.google.android.gms:play-services-maps:9.0.0"
    compile "com.google.android.gms:play-services-gcm:9.0.0"
    compile "com.google.android.gms:play-services-location:9.0.0"
    compile ('com.appyvet:materialrangebar:1.3')
        { exclude group: 'com.android.support' }
    compile 'com.google.code.gson:gson:2.5'
    compile "com.amazonaws:aws-android-sdk-s3:2.2.10"
    compile "com.amazonaws:aws-android-sdk-core:2.2.10"
    compile ('com.instabug.library:instabug:2.1')
        { exclude group: 'com.android.support' }
    compile 'com.github.tony19:logback-android-core:1.1.1-4'
    compile 'com.github.tony19:logback-android-classic:1.1.1-4'
    compile 'org.slf4j:slf4j-api:1.7.6'
    compile 'ch.acra:acra:4.8.2'
    compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.15'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.android.support:multidex:1.0.0'
}

您有重复的依赖项。看起来您同时使用了两个版本的Google Places API。 - Emmanuel
@Emmanuel 我也是这么想的。但是,我只使用了 Google Places API 的一个依赖项。我看不出它在哪里可以重复使用!! - HiddenDroid
1
在终端上运行 ./gradlew :android:dependencies。你使用的其他库可能依赖于 Google Places 库的早期版本。你需要找到引入该依赖项的库并从中排除 Google Places。 - Emmanuel
@Emmanuel 我还是找不到它。还有其他的事情要做吗? - HiddenDroid
另一个遇到相同问题的人描述说,通过查找其他包含模块中的build.gradle文件中的com.google.android.gms来解决了该问题...请参见链接:https://medium.com/@suchydan/how-to-solve-google-play-services-version-collision-in-gradle-dependencies-ef086ae5c75f - drewster
2个回答

20

我已将 Google Play 服务(地图、位置和 GCM)从9.0.0升级到9.2.0。

compile 'com.google.android.gms:play-services-location:9.2.0'
compile 'com.google.android.gms:play-services-maps:9.2.0'
compile 'com.google.android.gms:play-services-gcm:9.2.0'

然后我添加了这个依赖:

compile 'com.google.android.gms:play-services-places:9.2.0'

它的效果非常好 :)


0

我从https://developers.google.com/android/guides/releases添加了最新版本的com.google.android.gms,并为我使用的gms模块添加了force = true

    compile('com.google.android.gms:play-services-analytics:11.0.2') {
        force = true;
    }
    compile('com.google.android.gms:play-services-ads:11.0.2') {
        force = true;
    }
    compile('com.google.android.gms:play-services-gcm:11.0.2') {
        force = true;
    }

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