重复条目 Google Gson
Duplicate Entry Google Gson
我的错误:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
我正在尝试使用 Stripe 并将其与改造集成。我有 Stripe lib build.gradle 文件和应用程序 build.gradle 文件。
我没有看到是什么导致了这个错误,我需要在两个 build.gradle 文件中依赖,因为 Stripe 和 Retrofit 都使用它。
应用build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.weaverprojects.stripe2"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':stripe')
//compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.code.gson:gson:2.3'
compile 'org.parceler:parceler:0.2.13'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup:otto:1.3.6'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
}
条纹build.gradle:
apply plugin: 'com.android.library'
dependencies {
// compile 'com.stripe:stripe-java:1.15.1'
// compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/gson-2.2.4.jar')
compile files('libs/stripe-java-1.15.1.jar')
}
android {
compileSdkVersion 21
buildToolsVersion '23.0.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 21
multiDexEnabled = true
}
}
我的 libs 文件夹中确实有 Stripe 和 GSON jar,所以我尝试更改:
compile 'com.google.code.gson:gson:2.3'
至
compile files('../stripe/libs/gson-2.2.4.jar')
在应用程序的 build.gradle 中。
我做错了什么?
提前致谢。
问题的根源在于您混合了对通过 compile files('libs/gson-2.2.4.jar')
的 jar 和通过 compile 'com.google.code.gson:gson:2.3'
的 Maven 工件的依赖。
当您在项目的不同部分引用同一个 Maven 工件时,Gradle 能够智能地判断出它不应该同时包含两者。但是,Gradle 无法确定您引用的 jar 与您引用的 maven 工件相同。
解决方案
在 Stripes build.gradle 中,将 lib 引用更改为 compile 'com.google.code.gson:gson:2.3'
,并从您的项目中完全删除 gson-2.2.4.jar
。
要么删除行compile 'com.google.code.gson:gson:2.3'
或
从您的 lib 文件夹中删除 gson jar
。因为您在构建文件和 libs 文件夹中两次包含了库。
我的错误:
Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
我正在尝试使用 Stripe 并将其与改造集成。我有 Stripe lib build.gradle 文件和应用程序 build.gradle 文件。
我没有看到是什么导致了这个错误,我需要在两个 build.gradle 文件中依赖,因为 Stripe 和 Retrofit 都使用它。
应用build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.weaverprojects.stripe2"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':stripe')
//compile 'com.android.support:support-v4:18.0.+'
compile 'com.google.code.gson:gson:2.3'
compile 'org.parceler:parceler:0.2.13'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup:otto:1.3.6'
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.3.0'
}
条纹build.gradle:
apply plugin: 'com.android.library'
dependencies {
// compile 'com.stripe:stripe-java:1.15.1'
// compile 'com.google.code.gson:gson:2.2.4'
compile files('libs/gson-2.2.4.jar')
compile files('libs/stripe-java-1.15.1.jar')
}
android {
compileSdkVersion 21
buildToolsVersion '23.0.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 21
multiDexEnabled = true
}
}
我的 libs 文件夹中确实有 Stripe 和 GSON jar,所以我尝试更改:
compile 'com.google.code.gson:gson:2.3'
至
compile files('../stripe/libs/gson-2.2.4.jar')
在应用程序的 build.gradle 中。
我做错了什么?
提前致谢。
问题的根源在于您混合了对通过 compile files('libs/gson-2.2.4.jar')
的 jar 和通过 compile 'com.google.code.gson:gson:2.3'
的 Maven 工件的依赖。
当您在项目的不同部分引用同一个 Maven 工件时,Gradle 能够智能地判断出它不应该同时包含两者。但是,Gradle 无法确定您引用的 jar 与您引用的 maven 工件相同。
解决方案
在 Stripes build.gradle 中,将 lib 引用更改为 compile 'com.google.code.gson:gson:2.3'
,并从您的项目中完全删除 gson-2.2.4.jar
。
要么删除行compile 'com.google.code.gson:gson:2.3'
或
从您的 lib 文件夹中删除 gson jar
。因为您在构建文件和 libs 文件夹中两次包含了库。