0

I'm trying to use the new DiffUtil class that was introduced in recyclerview-v7:24.2.0.

However, I've discovered that updating my dependencies in my build.gradle makes it so that I can no longer run my app.

Below is my current list of dependencies which will build:

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'
}

All I do is change the one version number from 24.1.1 to 24.2.0 like so:

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'
}

If I make this change, my build fails with the following error:

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

I've tried setting up various exclusions for support modules, and I've tried using different prefixes for compilation (like androidTestCompile vs compile).

If anyone could make sense if what's going on and help me out, I'd be eternally grateful. Thanks.

aaronbatilo
  • 51
  • 1
  • 4

2 Answers2

1

add this to build.gradle file , you have duplicate dependency so this will exclude the collision

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

if above don't work then you can simply do

compile ('com.android.support:recyclerview-v7:+') {
    exclude module: 'support-v4'
}
Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68
  • If I do this, then I can't use anything from the support-v4 library, and I have code that still relies on that library. – aaronbatilo Sep 08 '16 at 16:13
  • no man , this will remove it from other during build but keep the original one – Pavneet_Singh Sep 08 '16 at 16:14
  • I tried adding it like this: https://gist.github.com/aaronjstar/46ad64c99ea9f305c7279255d35cc805 But this removed it from everything. How should I add it? – aaronbatilo Sep 08 '16 at 16:17
  • put it outside of dependency block, any-where – Pavneet_Singh Sep 08 '16 at 16:23
  • If I do that, I can't build anymore. Anything that's part of the support-v4 library can't be found anymore – aaronbatilo Sep 08 '16 at 16:29
  • you can try the updated answer to remove it form particular module – Pavneet_Singh Sep 08 '16 at 16:31
  • When I try the new answer I still have the same exception: `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` – aaronbatilo Sep 08 '16 at 16:37
  • try the gradle dependency view to find duplicate dependency using studio,steps : https://developer.android.com/studio/build/build-variants.html then use exclude command for every duplicate one for this try http://stackoverflow.com/questions/30648172/gradle-library-duplicates-in-dependencies – Pavneet_Singh Sep 08 '16 at 16:49
0

Clean and Rebuild the project in Android Studio or via gradle command.

Command in gradle to do so
./gradlew clean

Shadab K
  • 1,677
  • 1
  • 16
  • 25