Android build Gradle在特定设备上失败 [英] Android build gradle fail on specific device

查看:64
本文介绍了Android build Gradle在特定设备上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个奇怪的问题:当我编译应用以使其在具有android 7.0的设备上运行时,它可以工作,但是当我尝试为具有android 4.2.1的设备进行编译时,它将失败并显示以下错误:

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:

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

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

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

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

如果有人有一个主意...因为我尝试了很多想法,例如从配置等中排除okhttp,但没有任何效果.

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

解决方案

我有零钱

//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

and change version of picasso to 2.5.2

最后添加:

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

推荐答案

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

You should use 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 ,请在下面添加

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

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

这篇关于Android build Gradle在特定设备上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆