Dhananjay Yadav
Dhananjay Yadav

Reputation: 21

How to resolve "TransformException: java.util.zip.ZipException: duplicate entry" in Android?

Error description:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/api/client/http/AbstractInputStreamContent.class

Here is my gradle code

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.richwebs.user.hohoride"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

packagingOptions{
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile('com.google.api-client:google-api-client-android:1.20.0') {
    exclude group: 'org.apache.httpcomponents'
}

compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.google.android.gms:play-services-base:9.0.2'
compile 'com.google.android.gms:play-services-analytics:9.0.2'
compile 'com.google.android.gms:play-services-maps:9.0.2'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services-ads:9.0.2'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.google.android.gms:play-services-gcm:9.0.2'
compile group: 'commons-io', name: 'commons-io', version: '2.0.1'

}
android {
useLibrary 'org.apache.http.legacy'
}

Upvotes: 2

Views: 4388

Answers (2)

Sagar Chavada
Sagar Chavada

Reputation: 5269

there is a two way to solve this problem

  1. if method refrences in your app exceeds its limit then increase heapsize like this.

dexOptions { preDexLibraries = false javaMaxHeapSize "4g" }

and also enable mutidexSupport like this:

defaultConfig {

        multiDexEnabled true
    }

dependencies {   
    compile 'com.android.support:multidex:1.0.1'
}

and also set name attribute in your manifest file:

<application
        android:name="android.support.multidex.MultiDexApplication" >
</application>
  1. if this will not work then you have only one option and its exclude repeated library in you gradle file. this error called "already added" and its happen when you add .jar file in lib. folder and also set gradle dependency for this.

here is my full gradle file code..

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"
    useLibrary 'org.apache.http.legacy'

    dexOptions {
        preDexLibraries = false
        javaMaxHeapSize "4g"
    }

    defaultConfig {
        applicationId "com.apple"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    packagingOptions {
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE-FIREBASE.txt'
        exclude 'META-INF/NOTICE'
    }
}

dependencies {
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-v4:23.3.0'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    compile project(':library')
    compile files('libs/httpmime-4.3.jar')
    compile files('libs/gcm.jar')
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.google.code.gson:gson:2.4'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.firebase:firebase-client-android:2.3.1'
    compile files('libs/httpcore-4.3.2.jar')
    compile files('libs/httpclient-4.3.3.jar')
}

configurations {
    all*.exclude group: 'com.android.support', module: 'support-vector-drawable'
    all*.exclude group: 'com.android.support', module: 'animated-vector-drawable'
    all*.exclude group: 'com.android.support', module: 'support-annotations'
}

i have a problem with this three module so o just exclude from all dependency, and my error gone.

Upvotes: 1

Ognev Zair
Ognev Zair

Reputation: 1626

Maybe problem in different versions of imported libs

You have

  compile 'com.google.android.gms:play-services-analytics:9.0.0' // wrong!
  compile 'com.google.android.gms:play-services-gcm:9.0.2'

Make sure, that you always use same versions like:

  compile 'com.google.android.gms:play-services-analytics:9.0.2'
  compile 'com.google.android.gms:play-services-gcm:9.0.2'

Upvotes: 0

Related Questions