任务':app:packageAllDebugClassesForMultiDex'的Android工作室执行失败

Jey*_*y10 6 android google-play-services android-studio

我有这个错误:

Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzrf.class
Run Code Online (Sandbox Code Playgroud)

我想将google play服务添加到我的项目中,所以我把这行放在build.gradle文件中:

compile 'com.google.android.gms:play-services:7.8.0'
Run Code Online (Sandbox Code Playgroud)

所以我必须启用multidex并且我遵循android doc,在build.gradle中添加它:

compile 'com.android.support:multidex:1.0.1'
Run Code Online (Sandbox Code Playgroud)

multiDexEnabled true
Run Code Online (Sandbox Code Playgroud)

我在android清单中添加了这个:

<application 
...
android:name="android.support.multidex.MultiDexApplication">
Run Code Online (Sandbox Code Playgroud)

但我有上面写的错误.我发现了很多关于这个问题的问题(app:packageAllDebugClassesForMultiDex)但没有找到(重复条目:com/google/android/gms/internal/zzrf.class).

我尝试了一些解决方案,比如删除一些谷歌库,但我不知道是什么引用内部/ zzrf.class.

这是我的gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "fr.djey.testgoogleplus"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.android.support:multidex:1.0.1'
}
Run Code Online (Sandbox Code Playgroud)

mic*_*ael 10

我遇到了同样的问题.在我的情况下,我使用了我的Android应用程序使用的自制Android库.这意味着1个项目有2个独立的模块,而app模块依赖于库模块.两者都支持multidex.根本原因是谷歌播放服务版本之间的不一致.在app模块中,我使用了7.8.+,在库中,我使用了8.1.+.所以我刚刚更新到相同的8.1.+,这对我来说是固定的.所以我的答案是检查你所依赖的所有库,其中一个可能使用你下面的谷歌播放服务版本.