我知道我遇到的同样错误也有类似的问题,但实际上并没有一个对我有用。问题是,当我尝试将GsonConverterFactory
与 Retrofit客户端一起使用时,它会给我这个错误。
Error:Execution failed for task ':client:transformClassesWithJarMergingForOCStagingDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
确实有一个解决方案,它实际上建议我以下列方式从gson
库中删除com.squareup.retrofit2:converter-gson:2.1.0
模块 -
compile ('com.squareup.retrofit2:converter-gson:2.1.0') {
exclude group: 'com.google.code.gson.annotations', module: 'annotations'
}
但如果我这样做,那么GsonCoverter
就会停止工作,所有网络请求都会失败。
我在下面添加了所有依赖项的详细信息。
dependencies {
// Using sfl4j allows us to replace different loggers later, if desired
compile 'org.slf4j:slf4j-api:1.7.21'
compile project(':adyen')
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:appcompat-v7:22.0.+'
compile 'com.google.code.findbugs:jsr305:3.0.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.1.1'
compile('com.miairline:domain:5.1.19') {
exclude group: 'org.slf4j'
exclude group: 'log4j'
exclude group: 'commons-logging'
exclude group: 'org.apache.httpcomponents'
}
compile 'android.tools.support:annotations:20.0.1'
compile 'com.alexgilleran:icesoap:1.0.2'
compile 'commons-validator:commons-validator:1.4.0'
compile 'org.apache.commons:commons-lang3:3.0'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.7'
compile 'com.samskivert:jmustache:1.10'
compile 'org.alljoyn.bus:alljoyn-android:15.04.00a'
compile 'com.radaee.pdfex:com-radaee-pdfex:2.6.2'
compile 'com.adyen.services:android-lib:1.10p7'
compile 'net.christophersnow:sync-android-p2p:0.0.6-RC3'
compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true
}
compile 'com.iecisa:mposplugin_production:1.25@aar'
compile('org.restlet.jse:org.restlet:2.1-M7') {
exclude group: 'org.osgi', module: 'org.osgi.core'
}
compile 'org.restlet.jse:org.restlet.ext.simple:2.1-M7'
testCompile('junit:junit:4.10',
'org.slf4j:slf4j-simple:1.7.21',
'org.hamcrest:hamcrest-integration:1.3',
'com.miairline.test.uiautomator:uiautomator:18',
'org.robolectric:robolectric:2.0',
'org.powermock:powermock-api-mockito:1.5.1',
'org.powermock:powermock-core:1.5.1',
'org.powermock:powermock-api-easymock:1.5.1',
'com.github.rtyley:android-screenshot-celebrity:1.9')
compile 'com.akexorcist:RoundCornerProgressBar:2.0.3'
compile 'com.github.bmarrdev:android-DecoView-charting:v0.9.6'
compile ('com.squareup.retrofit2:retrofit:2.1.0') {
exclude group: 'com.google.code.gson', module: 'gson'
}
compile ('com.squareup.retrofit2:converter-gson:2.1.0') {
exclude group: 'com.google.code.gson.annotations', module: 'annotations'
}
compile('io.socket:socket.io-client:0.8.2') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}
compile('com.github.bright:slf4android:0.1.3') {
transitive = true
}
}
我还尝试查看依赖树,发现那里没有任何重复。奇怪的是,它正在为其他项目而不是在这个项目中工作。同时为defautlConfig
build.gradle
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
multiDexEnabled true
}