我正在使用android studio。在我的项目中,我尝试编译两个库。
两者都是.Jar文件使用不同的GSON版本。 当我编译我的项目时,我得到以下错误
错误:任务'执行失败:cloudAndroid:packageAllDebugClassesForMultiDex'。
java.util.zip.ZipException:重复条目:com / google / gson / annotations / Expose.class
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name: 'mp_library', ext: 'aar')
compile files('libs/aws-android-sdk-core-2.2.6.jar')
compile files('libs/aws-android-sdk-s3-2.2.6.jar')
}
你能帮我吗?非常感谢。
答案 0 :(得分:1)
您可以从AWS或Mp_library.jar中排除GSON库的一个传递依赖项。语法是
compile files('libs/aws-android-sdk-s3-2.2.6.jar') {
exclude group: 'com.google.code.gson', module: 'gson'
}
由于你使用gradle可能最好引用maven存储库依赖,而不是下载jar。
答案 1 :(得分:1)
这对我来说效果非常好。在我的情况下,我使用Signalr Android SDK并且改造了两者都有gson依赖关系我将它们从库中排除并将gson作为独立添加到项目中并且我的APK构建成功并且所有网络来自改造和SignalR的呼叫成功返回
//compile files('libs/gson-2.2.2.jar')
compile files('libs/signalr-client-sdk.jar')
compile 'com.google.code.gson:gson:2.8.1'
compile files('libs/signalr-client-sdk-android.jar')
compile ('com.squareup.retrofit2:retrofit:2.3.0'){
transitive=true;
exclude module: 'gson'
}
compile ('com.squareup.retrofit2:converter-gson:2.3.0'){
transitive=true;
exclude module: 'gson'
}
答案 2 :(得分:0)
在build.gradle文件中使用此行
defaultConfig {
multiDexEnabled = true
}