重复条目:com/google/android/maps/GeoPoint.class

duplicate entry: com/google/android/maps/GeoPoint.class

我正在使用 Android studio,当我生成签名的 APK 时显示错误:

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/maps/GeoPoint.class

我的依赖:

dependencies {

    //compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile files('libs/google-api-client-1.10.3-beta.jar')
    compile files('libs/google-http-client-1.10.3-beta.jar')
    compile files('libs/google-http-client-android2-1.10.3-beta.jar')
    compile files('libs/google-oauth-client-1.10.1-beta.jar')
    compile files('libs/gson-2.1.jar')
    compile files('libs/guava-11.0.1.jar')
    compile files('libs/jackson-core-asl-1.9.4.jar')
    compile files('libs/jsr305-1.3.9.jar')
    compile files('libs/protobuf-java-2.2.0.jar')
    compile files('libs/android-support-v4.jar')
    //compile files('libs/android-google-maps-api13.jar')
    //apply plugin: 'com.google.gms.google-services'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.android.support:support-v4:24.1.0'
    compile 'com.google.android.gms:play-services-auth:9.6.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.google.android.gms:play-services:9.6.1'
    compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
    compile 'com.koushikdutta.ion:ion:2.1.7'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'junit:junit:4.12'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
    testCompile 'junit:junit:4.12'

}

我该如何解决?

我做了以下事情:

  • 删除了重复的 jar 与 maven 依赖关系
  • 组织配置:compile、testCompile、androidTestCompile
  • 确保 testCompile 依赖项和编译依赖项没有混合

试试这个:

dependencies {  
    // apply plugin: 'com.google.gms.google-services'
    // compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    // compile 'com.google.android.gms:play-services:9.6.1' <-- this is too big, only use the modules you need
    // compile 'junit:junit:4.12' <-- wrong configuration
    // compile files('libs/android-google-maps-api13.jar')
    // compile files('libs/android-support-v4.jar') <-- you already have this added
    // compile fileTree(include: ['*.jar'], dir: 'libs') <- try not to use jars

    compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha9'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.google.android.gms:play-services-auth:9.6.1'
    compile 'com.koushikdutta.ion:ion:2.1.7'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.weiwangcn.betterspinner:library-material:1.1.0'
    // Try not to use jars, use maven dependencies 
    compile files('libs/google-api-client-1.10.3-beta.jar')
    compile files('libs/google-http-client-1.10.3-beta.jar')
    compile files('libs/google-http-client-android2-1.10.3-beta.jar')
    compile files('libs/google-oauth-client-1.10.1-beta.jar')
    compile files('libs/gson-2.1.jar')
    compile files('libs/guava-11.0.1.jar')
    compile files('libs/jackson-core-asl-1.9.4.jar')
    compile files('libs/jsr305-1.3.9.jar')
    compile files('libs/protobuf-java-2.2.0.jar')

    testCompile 'junit:junit:4.12'

    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}