重复录入Google Gson

Kei*_*ith 8 android gson stripe-payments build.gradle android-gradle-plugin

我的错误:

 Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
 > java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用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'
}
Run Code Online (Sandbox Code Playgroud)

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
    }
}
Run Code Online (Sandbox Code Playgroud)

我在libs文件夹中有Stripe和GSON jar,所以我尝试更改:

compile 'com.google.code.gson:gson:2.3'
Run Code Online (Sandbox Code Playgroud)

compile files('../stripe/libs/gson-2.2.4.jar')
Run Code Online (Sandbox Code Playgroud)

在应用程序的build.gradle中.

我究竟做错了什么?

提前致谢.

Sam*_*zor 19

问题的根源在于你将jar依赖于jar compile files('libs/gson-2.2.4.jar')和maven artifact 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.