且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

com.android.build.api.transform.TransformException:java.util.zip.ZipException:duplicate entry:com / google / android / gms / common / api / zza.class

更新时间:2023-11-19 08:57:34

此问题可能是因为您有重复的依赖关系。一个有最新版本,另一个有旧版本。



您可以做的是


  1. 检查您的应用依赖项。

      ./ gradlew clean:app:dependencies 


  2. 查找包含com.google.android.gms的第三方库。


  3. 排除此

      compile('library'){
    exclude group:'com.google.android.gms '
    }


这可能是能够快速解决。但是这不是很好!



***的解决方案应该是更新你的第三方库,他们的最新版本可能已经更新了他们的谷歌服务库。


Below is the error I am getting after adding the Firebase, google services in gradle and google-services.json in app module.

I have 13 modules in my app. I have 7 build variants in all the modules. I tried with placing the google-services.json in app module and placing it in build variant folder inside the app module. I am getting same error. I have the notification feature in one build variant.

I removed the firebase related code in gradle and google-services.json from application, it is working perfectly.

Due to security reason I can't share the entire file.

Main app module gradle:

dependencies {
   compile fileTree(include: ['*.jar'], dir: 'libs')
   testCompile 'junit:junit:4.12'
   debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
   releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
   testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
   compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
       transitive = true;
   }
   compile 'com.android.support:appcompat-v7:23.4.0'
   compile 'com.android.support:design:23.4.0'
   compile 'com.android.support:support-v4:23.4.0'
   compile 'com.jakewharton:butterknife:8.2.1'
   apt 'com.jakewharton:butterknife-compiler:8.2.1'
   compile 'com.github.hotchemi:permissionsdispatcher:2.0.7'
   apt 'com.github.hotchemi:permissionsdispatcher-processor:2.0.7'
   compile 'org.greenrobot:eventbus:3.0.0'
   compile 'com.android.support:multidex:1.0.1'

}

In Application gradle:

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.3'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

    classpath 'com.google.gms:google-services:3.0.0'
}

:app:transformClassesWithJarMergingForSmePreDebug FAILED FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForSmePreDebug'.>

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/api/zza.class

I reffered many links in *** for this issue. None fixed my problem. Any suggestions appreciated.

Edited push notification module gradle:

dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.4.0'
   //compile 'com.google.android.gms:play-services-gcm:9.0.0'

   compile 'com.google.firebase:firebase-messaging:9.8.0'
   //compile ('com.google.firebase:firebase-messaging:9.8.0') {
      //exclude group: 'com.google.android.gms'
   //}
}
apply plugin: 'com.google.gms.google-services'

This issue might because you have duplicate dependencies. One has latest version and the other one has old version.

What you can do is

  1. check your app dependecies.

    ./gradlew clean :app:dependencies
    

  2. find 3rd party libraries that also have com.google.android.gms included.

  3. exclude this group from the library

    compile ('library') {
        exclude group: 'com.google.android.gms' 
    }
    

This might be able to be a quick fix. But it's not good!

The best solution should be updating your 3rd party library, their latest version might update their google services library already.