RecyclerView-v7:24.2.0导致ZipException

时间:2016-09-08 15:47:29

标签: java android gradle android-recyclerview

我正在尝试使用recyclelerview-v7:24.2.0中引入的新DiffUtil类。

但是,我发现在build.gradle中更新我的依赖项会使我无法再运行我的应用程序。

以下是将构建

的当前依赖项列表
dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')

  compile 'com.android.support:recyclerview-v7:24.1.1'

  compile 'com.android.support:multidex:1.0.1'
  compile 'com.android.support:cardview-v7:24.2.0'
  androidTestCompile 'com.android.support:support-annotations:24.2.0'
  androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
  androidTestCompile 'com.android.support.test:runner:0.5'
  compile 'com.github.siyamed:android-shape-imageview:0.9.3@aar'
  compile 'com.neovisionaries:nv-websocket-client:1.12'
  compile 'com.nightonke:jellytogglebutton:1.0.2'
  compile 'com.squareup.okhttp3:okhttp:3.4.0-RC1'
  compile 'com.squareup.picasso:picasso:2.5.2'
  compile 'de.greenrobot:eventbus:2.4.0'
  compile 'de.hdodenhof:circleimageview:2.0.0'
  compile('com.github.ozodrukh:CircularReveal:1.3.1@aar') {
    transitive = true;
  }
  compile 'com.jakewharton:butterknife:8.1.0'
  apt 'com.jakewharton:butterknife-compiler:8.1.0'
  compile 'io.reactivex:rxandroid:1.2.1'
  compile 'io.reactivex:rxjava:1.1.6'
  compile "com.github.fge:json-patch:1.9"
  apt 'com.squareup:javapoet:1.7.0'
  apt 'com.google.dagger:dagger-compiler:2.2'
  compile 'com.google.dagger:dagger:2.2'
  provided 'javax.annotation:jsr250-api:1.0'
  compile 'com.github.pwittchen:reactivenetwork:0.5.0'
  testCompile "junit:junit:4.12"
  testCompile "org.mockito:mockito-all:1.10.19"
  compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
    transitive = true;
  }
  debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
  releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
  testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
}

我所做的就是将一个版本号从 24.1.1 更改为 24.2.0 ,如下所示:

dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')

  compile 'com.android.support:recyclerview-v7:24.2.0'

  compile 'com.android.support:multidex:1.0.1'
  compile 'com.android.support:cardview-v7:24.2.0'
  androidTestCompile 'com.android.support:support-annotations:24.2.0'
  androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
  androidTestCompile 'com.android.support.test:runner:0.5'
  compile 'com.github.siyamed:android-shape-imageview:0.9.3@aar'
  compile 'com.neovisionaries:nv-websocket-client:1.12'
  compile 'com.nightonke:jellytogglebutton:1.0.2'
  compile 'com.squareup.okhttp3:okhttp:3.4.0-RC1'
  compile 'com.squareup.picasso:picasso:2.5.2'
  compile 'de.greenrobot:eventbus:2.4.0'
  compile 'de.hdodenhof:circleimageview:2.0.0'
  compile('com.github.ozodrukh:CircularReveal:1.3.1@aar') {
    transitive = true;
  }
  compile 'com.jakewharton:butterknife:8.1.0'
  apt 'com.jakewharton:butterknife-compiler:8.1.0'
  compile 'io.reactivex:rxandroid:1.2.1'
  compile 'io.reactivex:rxjava:1.1.6'
  compile "com.github.fge:json-patch:1.9"
  apt 'com.squareup:javapoet:1.7.0'
  apt 'com.google.dagger:dagger-compiler:2.2'
  compile 'com.google.dagger:dagger:2.2'
  provided 'javax.annotation:jsr250-api:1.0'
  compile 'com.github.pwittchen:reactivenetwork:0.5.0'
  testCompile "junit:junit:4.12"
  testCompile "org.mockito:mockito-all:1.10.19"
  compile('com.crashlytics.sdk.android:crashlytics:2.6.2@aar') {
    transitive = true;
  }
  debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
  releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
  testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
}

如果我进行此更改,我的构建将失败,并显示以下错误:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/view/PagerTitleStrip$PageListener.class

我已经尝试为支持模块设置各种排除项,我尝试使用不同的前缀进行编译(如androidTestCompile vs compile)。

如果有人能够理解正在发生什么并帮助我,我会永远感激。感谢。

2 个答案:

答案 0 :(得分:1)

将此添加到build.gradle文件,您有重复的依赖项,因此这将排除冲突

configurations {
    all*.exclude group: 'com.android.support', module: 'support-v4'
}

如果上面没有工作,那么你可以简单地做

compile ('com.android.support:recyclerview-v7:+') {
    exclude module: 'support-v4'
}

答案 1 :(得分:0)

在Android Studio中或通过gradle命令清理并重建项目。

在gradle中执行命令 ./gradlew clean