2

I'm facing a strange problem : When I compile my app to run it on a device with android 7.0 it works but when I am trying to compile for a device with android 4.2.1 it fails with that error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/squareup/okhttp/Address.class

I don't understand why, I think it is cause by a problem of the build gradle file. Here is my gradle file:

apply plugin: 'com.android.application'

apply plugin: 'me.tatarka.retrolambda' // make sure to apply last!

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.qsmart.illicity"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        multiDexEnabled true
    }

    applicationVariants.all { variant ->
        variant.resValue "string", "versionName", variant.versionName
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dexOptions {
        preDexLibraries = false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile "com.android.support:support-v4:25.2.0"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.android.support:cardview-v7:25.2.0'
    compile 'com.android.support:recyclerview-v7:25.2.0'

    compile 'com.mikhaellopez:circularimageview:3.0.2'
    compile 'com.jakewharton:butterknife:8.5.1'
    compile('org.apache.commons:commons-io:1.3.2'){
        exclude module: 'commons-io'
    }
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.github.bumptech.glide:glide:3.8.0'
    compile 'com.github.lsjwzh.RecyclerViewPager:lib:v1.1.2@aar'
    /*For Slider*/
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
    /*End For Slider*/

    /*gauge*/
    compile 'pl.pawelkleczkowski.customgauge:CustomGauge:1.0.3'
    /*end of gauge*/

    annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    testCompile 'junit:junit:4.12'
}

If someone have an idea ... Because I tried a lot of thinks like exclude okhttp from configuration etc but nothing have work.

SOLUTION

I have change

//compile 'com.squareup.okhttp:okhttp:2.4.0'
//compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'

by

compile 'com.squareup.okhttp3:okhttp:3.8.1'

and change version of picasso to 2.5.2

and finally added:

configurations{
    all*.exclude module: 'okhttp'
    all*.exclude module: 'okio'
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Buisson
  • 479
  • 1
  • 6
  • 23

2 Answers2

2

You should use okhttp3:okhttp:n.n1.n2

compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.picasso:picasso:2.5.2'

If you receive duplicate entry: okio/AsyncTimeout$1.class Then add below

android {
  configurations{
     all*.exclude module: 'okhttp'
     all*.exclude module: 'okio'
   }
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

Try to use only one dependency.

compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
Purushotam Kumar
  • 1,002
  • 2
  • 13
  • 23