7

Immediately after adding the facebook-audience-network-sdk in my gradle file, I started getting errors, the first one I fixed my adding multiDexEnabled true, after that I keep getting this error

Execution failed for task ':app:transformClassesWithJarMergingForDebug'.

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

Here are my dependencies list in build.gradle

 dependencies {
   compile fileTree(dir: 'libs', include: ['*.jar'])
   testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:23.1.1'
   compile 'com.mcxiaoke.volley:library:1.0.17'
   compile 'com.android.support:recyclerview-v7:23.1.1'
   compile 'com.android.support:design:23.1.1'

   compile 'com.google.android.gms:play-services-gcm:8.4.0'
   compile 'com.google.android.gms:play-services-auth:8.4.0'
   compile 'com.google.android.gms:play-services-analytics:8.4.0'

   compile 'com.facebook.android:facebook-android-sdk:4.10.0'
   compile 'com.facebook.android:audience-network-sdk:4.10.0'
   compile 'joda-time:joda-time:2.7'
 }

After running gradle with -q dependencies here is my screenshot, I think the problem is related to google play services libraries seeing the facebook.android:audience-network-sdk depends on analytics 7.8.0 while I have included the latest 8.4.0 already in my dependencies, I'm not sure. How can i fix this? enter image description here

user3564573
  • 680
  • 1
  • 12
  • 24
  • play-services-base:7.8.0 and 8.4.0 are likely conflicting – OneCricketeer Feb 12 '16 at 03:50
  • Also, `4.10.0` are the [latest versions](https://search.maven.org/#search%7Cga%7C1%7Ccom.facebook.android) for both the facebook sdks. (If you wanted them) – OneCricketeer Feb 12 '16 at 03:54
  • @cricket_007 I have updated to the latest sdk, I see it still depends on google play services 8.1.0 while I'm compiling on 8.4.0. Still the same error, still trying to fix the issue. – user3564573 Feb 12 '16 at 04:16
  • Just googling "ZipException: duplicate entry" comes up with several hits, but it basically comes down to excluding parts of one library from gradle – OneCricketeer Feb 12 '16 at 04:17

1 Answers1

13

I finally got rid of the error. So the problem was with the com.google.android.gms:play-services-ads-8.1.0. You can see from the image it was 8.1.0 and other play dependencies were 8.4.0.

So these two ways worked. One was to change the dependency into

 compile ('com.facebook.android:facebook-android-sdk:4.10.0'){
    exclude group:"com.google.android.gms"
 }

But the issue with this is that, it could be a problem since in my other dependencies I didn't have play-services-ads:8.4.0'

So the way I solved this was just add a single line

  compile 'com.google.android.gms:play-services-ads:8.4.0'

This way everything worked perfectly, because when gradle compiled it automatically replaced the 8.1.0 into the 8.4.0

Here is my final dependencies list that worked

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.1.1'
     compile 'com.mcxiaoke.volley:library:1.0.17'
     compile 'com.android.support:recyclerview-v7:23.1.1'
     compile 'com.android.support:design:23.1.1'

     compile 'com.google.android.gms:play-services-gcm:8.4.0'
     compile 'com.google.android.gms:play-services-auth:8.4.0'
     compile 'com.google.android.gms:play-services-analytics:8.4.0'

     compile 'com.google.android.gms:play-services-ads:8.4.0'

     compile 'com.facebook.android:facebook-android-sdk:4.10.0'
     compile 'com.facebook.android:audience-network-sdk:4.10.0'
     compile 'joda-time:joda-time:2.7'

}

user3564573
  • 680
  • 1
  • 12
  • 24
  • This should work as long as there are no changes in the play-services-ads api from version 8.1.0 to 8.4.0 that would break the facebook sdk. – Rohan Feb 12 '16 at 06:31
  • Sure! It works fine, the ads show up, and the clicks are counted. I guess thats the important part – user3564573 Feb 12 '16 at 06:58
  • @Rohan that is the expected behaviour as you can see on the screenshot Gradle anyway always replace old dependencies with the newer versions. – Pedro Hidalgo May 17 '17 at 12:35