3

I am Importing my project from Eclipse , while building an APK i found following Error.

Error:Execution failed for task

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/plus/PlusOneButton$OnPlusOneClickListener.class

Error:Execution failed for task ':gruhini:transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/games/Game.class

Error:Execution failed for task ':gruhini:transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/auth/GoogleAuthException.class

Error:Execution failed for task ':gruhini:processDebugGoogleServices'.

Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at https://bintray.com/android/android-tools/com.google.gms.google-services/) or updating the version of com.google.android.gms to 9.0.0.

my build.gradle:

   apply plugin: 'com.android.application'

   android {
           compileSdkVersion 24
           buildToolsVersion "24.0.3"
           useLibrary 'org.apache.http.legacy'

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

defaultConfig {
    applicationId "com.gruhini"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}



buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}
dexOptions {
    incremental true
    preDexLibraries false
    //javaMaxHeapSize "1G" // 2g should be also OK
      }
      }

     dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':eclipseProject')
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/google-play-services.jar')
compile files('libs/httpclient-4.1.jar')
compile files('libs/httpcore-4.1.jar')
compile files('libs/httpmime-4.1.jar')
compile files('libs/itextpdf-5.2.1.jar')
compile files('libs/mail.jar')
compile files('libs/mpandroidchartlibrary-1-7-4.jar')
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
compile 'com.google.android.gms:play-services:10.2.0'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'

  }
  • try this for your code android{ configurations { all*.exclude group: 'com.android.support', module: 'support-annotations' } ] – Learning Always Mar 14 '17 at 09:27
  • you add google-play-services.jar as well as com.google.android.gms:play-services:10.2.0 – Avani Paneliya Mar 14 '17 at 09:28
  • I tried to hide the code of compile files('libs/google-play-services.jar') . Still it reflects the same error. –  Mar 14 '17 at 09:33

4 Answers4

1

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/plus/

Problem

compile files('libs/google-play-services.jar') // Remove this line
compile 'com.google.android.gms:play-services:10.2.0' //10.0.1 or 9.6.0

Both are same .Call one of them . Then Clean-Rebuild and Run .

Try with this App Level build.gradle

    apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.1"

    dexOptions {
        javaMaxHeapSize "4g"
    }
    defaultConfig {
        applicationId "com.gruhini"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 12
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        useLibrary 'org.apache.http.legacy'
        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'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
        testCompile 'junit:junit:4.12'
        compile project(':eclipseProject')
        compile files('libs/activation.jar')
        compile files('libs/additionnal.jar')
        compile files('libs/httpclient-4.1.jar')
        compile files('libs/httpcore-4.1.jar')
        compile files('libs/httpmime-4.1.jar')
        compile files('libs/itextpdf-5.2.1.jar')
        compile files('libs/mail.jar')
        compile files('libs/mpandroidchartlibrary-1-7-4.jar')
        compile 'com.android.support:support-v4:25.1.0'
        compile 'com.google.android.gms:play-services:10.0.1'
        compile 'com.android.support:appcompat-v7:25.1.0'
        compile 'com.android.support:design:25.1.0'

}

Project Level build.gradle

   // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2' //2.2.3
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    I removed that line , clean the project , rebuild project and while generating the apk same error found :( –  Mar 14 '17 at 09:50
  • 1
    @KevalShukla Restart your IDE – IntelliJ Amiya Mar 14 '17 at 09:50
  • @KevalShukla same problem ?? – IntelliJ Amiya Mar 14 '17 at 10:02
  • While downgrading the version of gms playservice(8.4.0) i found folllowing error . Error:Execution failed for task ':gruhini:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/games/Game.class –  Mar 14 '17 at 10:02
  • 1
    @KevalShukla call `9.6.0` – IntelliJ Amiya Mar 14 '17 at 10:04
  • 1
    By adding gms playservice (9.6.0) it found another error . Which i will add in the question tag . –  Mar 14 '17 at 10:08
  • 1
    When i add this line : apply plugin: 'com.google.gms.google-services' i found an error . I added that error in my question tag . –  Mar 14 '17 at 10:59
  • @KevalShukla add `com.google.android.gms:play-services:9.6.1` my answer http://stackoverflow.com/a/37406307/3395198 – IntelliJ Amiya Mar 14 '17 at 11:02
  • I use your dependencies in both file API level and Project Level . Now it reflects to the very first error that i have faced . :( –  Mar 14 '17 at 11:05
  • Could you please provide another solution.? @IntelliJ Amiya –  Mar 14 '17 at 11:57
0

Do inside Android in your gradle file like this.

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

instead of you write inside dex option.

your gradle file will looks like..

apply plugin: 'com.android.application'

     android {
               compileSdkVersion 24
               buildToolsVersion "24.0.3"
               useLibrary 'org.apache.http.legacy'
configurations {
                all*.exclude group: 'com.android.support', module:'support-annotations'
        }

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

    defaultConfig {
        applicationId "com.gruhini"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }



    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    dexOptions {
        incremental true
        preDexLibraries false
        //javaMaxHeapSize "1G" // 2g should be also OK
          }
          }

         dependencies {
         compile fileTree(dir: 'libs', include: ['*.jar'])
         androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

    })
    compile project(':eclipseProject')
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/google-play-services.jar')
    compile files('libs/httpclient-4.1.jar')
    compile files('libs/httpcore-4.1.jar')
    compile files('libs/httpmime-4.1.jar')
    compile files('libs/itextpdf-5.2.1.jar')
    compile files('libs/mail.jar')
    compile files('libs/mpandroidchartlibrary-1-7-4.jar')
    compile 'com.android.support:support-v4:24.2.1'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services:10.2.0'
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'

      }
Learning Always
  • 1,563
  • 4
  • 29
  • 49
0

It works Properly by Removing Following Lines from Gradle . compile fileTree(dir: 'libs', include: '*.jar')

0

There is a mismatch between the play-services versions being used in your packages (i.e. a package using version x, another package using version y).

None of the other answers explain why you should use play-services version x.y.z or how to check which one is applicable. You can check that with ./gradlew :app:dependencies

You will get an output similar to

|    \--- com.google.android.gms:play-services-tasks:10.2.6 --> (11.0.1)(*)
+--- com.google.android.gms:play-services-basement:11.0.1 (*)

```

From this output you can see the latest version of play-services being used in your project (in the above example it's 11.0.1). In your build.gradle file, you should specify this version for all play-services (they all must be the same version).

Franz
  • 154
  • 1
  • 10