Solution for TransformException

ElamParithi Arul
helloParithi
Published in
2 min readJun 15, 2016

So, this week in one of our projects, I had been working in integrating the YouTube API in our app. And of the things I had in that was to add Google Play Services API as a part of it. The integration was complete, everything ran fine but at the end while generating the APK, we got stuck with this error.

:app:transformClassesWithJarMergingForDebug'.
com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry:
/some/package/name/containing/SomeClass.class

Are you facing this error on your Android Project too?

I tried a few things to fix this,

First, I tried to clean up the dependencies based on a few sources from StackOverflow. To do this, Goto your project’s root folder and run the following :

./gradlew clean

But that didn’t help me out.

The Solution that worked,

This error is likely to occur if two or more of your dependencies have the same class in the package as other packages. To find that out, You could run the following command from your root project folder :

./gradlew dependencies

Or you can install the plugin “Android Methods Count”, by going to Android Studio > Preferences > Plugins. Type “Android Methods Count” and click “browse” below. On the popup that opens up, Click “Android Methods Count” and click “Install Plugin” at the side.

This will enable you to view the dependencies that your dependencies depend upon and will help you to exclude the dependencies that may have already added.

A clue would be the class path that you get in the error :

:app:transformClassesWithJarMergingForDebug'.
com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry:
com/google/common/base/FinalizableReference.java

In the error that I’ve got, we could see that the “FinalizableReference.java” is a part of the Guava Library by Google. To rectify this error, we need to look up for the dependencies that use the guava library and exclude it.

To find that out, goto your build.gradle file and check the dependencies by hovering over the blue circle to the left of th “compile…” code blocks. A tooltip will popup with the dependencies that are you used by your dependency package. In my case,

A screenshot from Android Studio

As you can see here, ‘com.google.apis:google-api-services-youtube:v3-rev175–1.22.0’ is using the module ‘guava-jdk5’. So by excluding that module,

compile ('com.google.apis:google-api-services-youtube:v3-rev175-1.22.0'){
exclude module: 'guava-jdk5'
}

By excluding this, I was able to fix this error.

Hope this helps you in rectifying yours. Let me know in the comments if you have any questions.

Happy coding :)

--

--

ElamParithi Arul
helloParithi

Loves to build beautiful products for the Internet.