Android,无法使用 Retrofit 和 RxJava 2 构建应用程序

Android, cannot build app with Retrofit and RxJava 2

这里是依赖项

compile 'com.squareup.retrofit2:retrofit:2.2.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.7'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit2:converter-gson:2.0.0'

当我尝试 运行 应用时出现此错误

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties File1: C:\Users\abondarenco.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava.0.7734c0092a5d3c3ec99510e50c1ff76bdf0c65a\rxjava-2.0.7.jar File2: C:\Users\abondarenco.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava.2.0bfaf64c94f3848ebf5cf1c2ea4ec9d1b3ac6c8\rxjava-1.2.0.jar

我尝试在没有 adapter-rxjava 的情况下 运行 应用程序并且它可以工作,但是当我添加适配器时它说有重复的文件,它下载 RxJava 1...

使用正确版本的适配器。

compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0'

我知道在这个帖子上回答已经太晚了,但我最近遇到了同样的问题,并且能够通过更新模块级别来解决这个问题 build.gradle 文件。

android {
  packagingOptions{
      exclude 'META-INF/rxjava.properties'
  }
}

希望能帮助一些人解决这个问题。