3

I am converting a project from Eclipse to Android Studio. It wasn't easy. I tried to put the AdMob banner and I got an error like this.

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/ads/identifier/AdvertisingIdClient$zza.class

There's only 1 AdvertisingIdClient$zza.class file in the project.
Why am I getting this error?
I have spent many hours on this, but no clues.
Can anyone help me, please?


Thanks for all replies. Here's my gradle files.

app-gradle >>>>

apply plugin: 'com.android.application'

android {
    compileSdkVersion 13
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "sw.ko.aaaaa.bbbbb"
        minSdkVersion 9
        targetSdkVersion 9
        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard.cfg'
        }
    }
}

dependencies {
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/commons-email-1.2.jar')
    compile files('libs/commons-net-2.0.jar')
    compile files('libs/google-play-services.jar')
    compile files('libs/mail.jar')
    compile files('libs/twitter4j-core-android-2.2.5.jar')
}

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

Another gradle file is...

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

allprojects {
    repositories {
        jcenter()
    }
}

External Libraries...

Android API 13 Platform
1.8
firebase-analytics-9.0.0
firebase-analytics-impl-9.0.0
firebase-common-9.0.0
firebase-core-9.0.0
firebase-iid-9.0.0
multidex-1.0.1
multidex-instrumentation-1.0.1
play-services-base-9.0.0
play-services-basement-9.0.0
play-services-tasks-9.0.0
support-v4-23.0.0
Kim Paul
  • 31
  • 3
  • This is usually caused when you use two libraries which both have a shared dependency so it tries to add them both to your compiled app. See this question for more details: http://stackoverflow.com/a/39388746/3061857 – nbokmans Feb 09 '17 at 08:45
  • There are various SO links for the same but from my personal experience when I tried migrating it was hell. After trying for a week. I gave up. Created new Andriod Studio project and copied code from eclipse to this one where ever required. – rohitanand Feb 09 '17 at 08:51
  • You need to show your `build.gradle`, please. – OneCricketeer Feb 09 '17 at 09:17
  • you can check if there are any duplicate libraries in External Libraries section. – Sagar Pujari Feb 09 '17 at 09:27
  • @Sourav Ganguly That's the last comment that I want to hear. TT. I already spent a whole day. I will try a little more and I may have to do as you said. T.,T – Kim Paul Feb 10 '17 at 01:50

1 Answers1

1

Remove all references to Google Play Services (JAR files and other Gradle lines)

Add this one for Admob

dependencies {
    ...

    compile 'com.google.android.gms:play-services-ads:10.0.1'
}

Add more dependencies for other Google or Firebase services.


I'd prefer to do it this way to keep all versions the same.

ext {
    // Variables to keep libraries consistent
    googlePlayServicesVersion = '10.0.1'
}

dependencies {
    ...

    compile "com.google.android.gms:play-services-ads:${googlePlayServicesVersion}"
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • I tried your 2nd suggestion and it worked!!!! Thank you so much. Now I have another problem which is 'java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.' Anyway, thank you again. :) – Kim Paul Feb 10 '17 at 02:50
  • The second suggestion is a refactoring of the first. You just needed to remove `compile files('libs/google-play-services.jar')` and add the others basically. You can use the checkmark next to my answer to accept it :) – OneCricketeer Feb 10 '17 at 03:55