Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Proguard Duplicate Definition

I'm attempting to add a 3rd party library (JmDNS) to my Android project.

I created a folder 'libs' under the base project directory, and dropped the jar file in the directory.

When I attempt to build he project using Ant (ant release), I receive a 'duplicate definition' notices for what appears to be each class in the JmDNS jar file.

....
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Canceler]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.DNSStateTask]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Prober]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.Renewer]
[proguard] Note: duplicate definition of library class [javax.jmdns.impl.tasks.state.package-info]
[proguard] Note: duplicate definition of library class [javax.jmdns.package-info]
[proguard] Note: there were 357 duplicate class definitions.

The build also fails with the following error:

BUILD FAILED
/path/Tools/ant-android-scala/build-scala.xml:183: Can't write [/path/bin/projectname-debug-shrinked.jar] (Can't read [/path/projectname/libs/jmdns.jar(;;;;!META-INF/MANIFEST.MF,!library.properties)] (Duplicate zip entry [jmdns.jar:javax/jmdns/JmDNS$Delegate.class]))

I've made sure that the jar file is only included once, and there is no other way that I am including duplicate source files anywhere in the project.

Why else would Proguard complain about duplicate definitions?

like image 476
Steve Avatar asked Jan 10 '12 15:01

Steve


Video Answer


2 Answers

Fixed this by moving the 3rd party libraries to another directory, in my case 'lib'. Then added

-injars lib/jmdns.jar 

to the proguard.cfg file.

If the 3rd party lbs are included in the 'libs' folder, then they are processed twice.

like image 76
Steve Avatar answered Oct 21 '22 06:10

Steve


In current progaurd version there is no need to specify injars. It is handled by default. This could be due to the following reasons-

1) duplicate jar files in some referenced libraries.

Solution - Removed it from the application and let it be reference library

2) Could be due to different gradle versions between your application gradle file and referenced library gradle file. Make it same.

Solution - Edit the gradle file to one of the referenced library's/Project's gradle file. See the classpath is same for both projects.

dependencies { classpath 'com.android.tools.build:gradle:1.3.0' }

I had both these problems, rectified it and it worked.

like image 31
Fenil Avatar answered Oct 21 '22 05:10

Fenil