Android构建gradle在特定设备上失败

时间:2017-08-23 08:13:24

标签: java android gradle

我面临一个奇怪的问题:当我编译我的应用程序以在具有android 7.0的设备上运行它时它可以正常工作,但是当我尝试为具有android 4.2.1的设备编译时它失败并出现该错误:

  

错误:任务':app:transformClassesWithJarMergingForDebug'的执行失败。   com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com / squareup / okhttp / Address.class

我不明白为什么,我认为这是由构建gradle文件的问题引起的。这是我的gradle文件:

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

如果有人有想法...因为我尝试了许多想法,从配置等排除okhttp但没有任何工作。

我有变化

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

通过

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

并将毕加索的版本更改为2.5.2

最后补充道:

configurations{
    all*.exclude module: 'okhttp'
    all*.exclude module: 'okio'
}

2 个答案:

答案 0 :(得分:2)

您应该使用 okhttp3:okhttp:n.n1.n2

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

如果您收到 duplicate entry: okio/AsyncTimeout$1.class ,请在下方添加

android {
  configurations{
     all*.exclude module: 'okhttp'
     all*.exclude module: 'okio'
   }
}

答案 1 :(得分:0)

尝试只使用一个依赖项。

128 Kms, ,$106.88
46 Kms, ,$174.14
169 Kms, ,$187.01
20 Kms, ,$205.43
94 Kms, ,$248.14
130 Kms, ,$266.07
97 Kms, ,$398.33
53 Kms, ,$401.53
179 Kms, ,$488.69
152 Kms, ,$493.87