重复录入Google Gson

时间:2015-09-29 19:03:33

标签: android gson android-gradle stripe-payments build.gradle

我的错误:

 Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
 > java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class

我尝试使用Stripe并将其与改造相结合。我有Stripe lib build.gradle文件和app build.gradle文件。

我没有看到导致此错误的原因,我需要两个build.gradle文件中的依赖项,因为Stripe和Retrofit都使用它。

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

Stripe 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')

在app的build.gradle中。

我做错了什么?

提前致谢。

2 个答案:

答案 0 :(得分:18)

问题的根源在于您通过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

答案 1 :(得分:0)

删除第compile 'com.google.code.gson:gson:2.3'

从lib文件夹中删除gson jar。因为您已在构建文件和libs文件夹中将库包含两次。