10

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?

Steve
  • 53,375
  • 33
  • 96
  • 141
  • a clean of the project managed to fix it for me (after trying a bunch of the suggested answers) seems a stale version of the lib was being kept around in the build folder or something – Fonix Jan 04 '16 at 03:19

2 Answers2

12

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.

Steve
  • 53,375
  • 33
  • 96
  • 141
  • I met the same error and solve it according to your answer -- BTW, I use full path for jars in line -injars ... Thank you for share your answer. – civic.LiLister Apr 26 '12 at 04:45
  • 5
    Or just `-injars libs` – shkschneider Dec 20 '13 at 09:54
  • Do you have two folders 'lib' and 'libs'? do you have in your gradle `compile fileTree(dir: 'libs', include: ['*.jar'])` ? – NickUnuchek Feb 25 '16 at 15:19
  • 1
    According to Proguard troubleshooting doc: **You should never explicitly specify the input jars yourself (with -injars or -libraryjars), since you'll then get duplicate definitions.** – IgorGanapolsky Oct 31 '16 at 15:49
1

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.

Fenil
  • 1,194
  • 10
  • 11