我面临一个奇怪的问题:当我编译我的应用程序以在 Android 7.0 的设备上运行它时,它可以工作,但是当我尝试为 Android 4.2.1 的设备进行编译时,它会失败并出现以下错误:
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 文件:
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'
并将picasso版本更改为2.5.2
最后添加:
configurations{
all*.exclude module: 'okhttp'
all*.exclude module: 'okio'
}
最佳答案
您应该使用 okhttp3:okhttp:n.n1.n2
compile 'com.squareup.okhttp3:okhttp:3.8.1'
compile 'com.squareup.picasso:picasso:2.5.2'
如果您收到重复条目:okio/AsyncTimeout$1.class
,请在下面添加
android {
configurations{
all*.exclude module: 'okhttp'
all*.exclude module: 'okio'
}
}
关于java - Android 构建 gradle 在特定设备上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45834219/