包含facebook sdk后出现Gradle错误

use*_*573 7 java android gradle facebook-sdk-4.0

在我的gradle文件中添加facebook-audience-network-sdk之后,我立即开始收到错误,第一个我修复了添加multiDexEnabled的错误,之后我不断收到此错误

任务':app:transformClassesWithJarMergingForDebug'的执行失败.

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/internal/zzqa.class

这是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'
 }
Run Code Online (Sandbox Code Playgroud)

在使用-q依赖项运行gradle之后是我的截图,我认为这个问题与google play服务库有关,看到facebook.android:audience-network-sdk依赖于7.8.0的分析,而我已经包含了最新的8.4.0在我的依赖中,我不确定.我怎样才能解决这个问题? 在此输入图像描述

use*_*573 13

我终于摆脱了错误.问题出在com.google.android.gms:play-services-ads-8.1.0上.您可以从图像中看到它是8.1.0,其他播放依赖项是8.4.0.

所以这两种方式都有效.一个是将依赖关系改为

 compile ('com.facebook.android:facebook-android-sdk:4.10.0'){
    exclude group:"com.google.android.gms"
 }
Run Code Online (Sandbox Code Playgroud)

但问题是,它可能是一个问题,因为在我的其他依赖项中,我没有播放服务广告:8.4.0'

所以我解决这个问题的方法就是添加一行

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

这样一切都运行得很好,因为当gradle编译时,它会自动将8.1.0替换为8.4.0

这是我的最终依赖列表

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'
Run Code Online (Sandbox Code Playgroud)

}