6

Building an app generates the following error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/appcompat/R$anim.class

I have cleaned and built the project many times to no avail. It has the following in its gradle build:

compile 'com.android.support:appcompat-v7:23.3.0'

It also uses a library via its aar file. That library project also has the above in its gradle build.

Could anyone offer a tip on how to resolve this?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Hong
  • 17,643
  • 21
  • 81
  • 142
  • Remove the duplicate. It's that simple. If you have an AAR file that already compiled something for you, then no need to compile it again. – OneCricketeer Apr 20 '16 at 06:52
  • @cricket_007 How can the duplicate be removed? I tried: exclude module: 'appcompat-v7', but it did not not help. Did you mean not including "compile 'com.android.support:appcompat-v7:23.3.0'"? The app needs appcompat-v7. There would be errors without it. – Hong Apr 20 '16 at 10:36
  • "It also uses a library via its AAR file" I'm assuming that AAR file also needed the appcompat library? Therefore you are likely having overlapping dependencies, therefore the error. Your code does not need that compile line if that AAR project already includes it – OneCricketeer Apr 20 '16 at 12:25
  • @cricket_007 Yes, the library, which produces the AAR file, also needs android.support.v7. Building the app would produce errors such as "Error:(10, 30) error: package android.support.v7.app does not exist" if that compile line is not needed. I did not want to complicate the case, so I did not mention that everything was working fine until I updated Android Studio and a bunch of other things recently. I believe there is a major upgrade of gradle. I suspect that is the culprit. – Hong Apr 20 '16 at 13:08
  • @cricket_007 I have finally found the culprit. It is indeed the recent gradle upgrade. Everything works fine now after changing classpath 'com.android.tools.build:gradle:1.0.0' to classpath 'com.android.tools.build:gradle:2.0.0'. I do not know why. The gradle stuff in Android Studio has been a graybox to me. If you could shed some light on this with an answer, I would love to accept it. – Hong Apr 20 '16 at 15:09
  • I wouldn't do something as drastic as `1.0.0`, try `1.5.0`... Anyways, I have no idea what the problem would be since I haven't bothered upgrading my Gradle settings in any project. You are welcome to read the changelog of Gradle stuff here http://tools.android.com/tech-docs/new-build-system – OneCricketeer Apr 20 '16 at 15:57
  • hi, I'm facing the same problem.. did you solved it? – Nahuel Barrios May 16 '16 at 21:22
  • @NahuelBarrios Yes as I described in my previous comment. – Hong May 16 '16 at 22:08

1 Answers1

5

Yup , Face same problem few days ago

Reason - as you told "That library project also has the above in its gradle build" actually system wont able to understand which dependency hi will take (app's - compile 'com.android.support:appcompat-v7:23.3.0' or module project's - compile 'com.android.support:appcompat-v7:23.3.0' ) so that hi says you have duplicate entry

How To Resolve -

Step 1 - Just Clean/Build Project. go to Build -> Clean/Build Project.

Step 2 - In terminal execute in root project folder ./gradlew clean*

Step 3- you have to exclude your group from one dependency

compile('com.android.support:design:23.2.1') {
    exclude group: 'com.android.support', module: 'support-v7'
}

Step 4 - Check Out This Awsome Answer https://stackoverflow.com/a/19022328/4741746

And Answer That Work for me is -

I just remove 1 dependency from apps level gradle and just put only in module project level gradle and also exclude support-v4 in which that anim class exist

  compile 'com.android.support:appcompat-v7:23.2.1'
        compile('com.android.support:design:23.2.1') {
            exclude group: 'com.android.support', module: 'support-v4'
        }
Community
  • 1
  • 1
Sushant Gosavi
  • 3,647
  • 3
  • 35
  • 55