重复条目 - Google Gson

8

我的错误:

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

我正在尝试使用Stripe并将其与retrofit集成。 我有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'
}

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

在应用程序的build.gradle文件中,我做错了什么吗?
提前感谢。
2个回答

19
问题的根源在于您通过compile files('libs/gson-2.2.4.jar')混合了对jar文件的依赖和Maven工件的依赖compile 'com.google.code.gson:gson:2.3'
当您在项目的不同部分引用相同的Maven工件时,Gradle能够智能地确定它不应该包含两个。但是,Gradle无法确定您引用的jar与Maven工件是相同的。
解决方案:在Stripes build.gradle中,将lib引用更改为compile 'com.google.code.gson:gson:2.3',并从项目中完全删除gson-2.2.4.jar

把我的一天都救了,谢谢。 - Qasim
我遇到了完全相同的错误,但是libs文件夹中没有该库的jar文件?而且我正在使用其依赖项下载Stripe,因此无法访问其gradle文件? - Alaa AbuZarifa

0

要么删除这一行代码 compile 'com.google.code.gson:gson:2.3'

或者

从你的lib文件夹中删除gson jar,因为你已经在构建文件和libs文件夹中重复引用了该库。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接