0

So I am aware of the page that describes the error in the simple case when you are including JUnit 4.10:

java.lang.IllegalArgumentException: already added: Lorg/hamcrest/BaseDescription; Conversion to Dalvik format failed with error 1

Unfortunately, I am using a library that depends on JUnit:

com.googlecode.json-simple:json-simple:jar:1.1.1

So I cannot add the exclusion. Here is the dependency tree:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ androidapp ---
[INFO] com.mycompany:androidapp:apk:0.1
[INFO] +- com.google.android:android:jar:2.3.3:provided
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:provided
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.0.1:provided
[INFO] |  |  \- org.apache.httpcomponents:httpcore:jar:4.0.1:provided
[INFO] |  +- org.khronos:opengl-api:jar:gl1.1-android-2.1_r1:provided
[INFO] |  +- xerces:xmlParserAPIs:jar:2.6.2:provided
[INFO] |  +- xpp3:xpp3:jar:1.1.4c:provided
[INFO] |  \- org.json:json:jar:20080701:provided
[INFO] +- com.google.android:support-v4:jar:r7:compile
[INFO] \- com.mycompany:api-client-java:jar:1.0:compile
[INFO]    +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO]    |  \- junit:junit:jar:4.10:compile
[INFO]    |     \- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO]    +- commons-io:commons-io:jar:2.4:compile
[INFO]    +- commons-codec:commons-codec:jar:1.9:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO]    +- ch.qos.logback:logback-core:jar:1.1.1:compile
[INFO]    \- ch.qos.logback:logback-classic:jar:1.1.1:compile

Here is the maven error:

[INFO] 
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lorg/hamcrest/BaseDescription;
[INFO]  at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
[INFO]  at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
[INFO]  at com.android.dx.command.dexer.Main.processClass(Main.java:685)
[INFO]  at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
[INFO]  at com.android.dx.command.dexer.Main.access$600(Main.java:78)
[INFO]  at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
[INFO]  at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
[INFO]  at com.android.dx.command.dexer.Main.processOne(Main.java:596)
[INFO]  at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
[INFO]  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
[INFO]  at com.android.dx.command.dexer.Main.run(Main.java:230)
[INFO]  at com.android.dx.command.dexer.Main.main(Main.java:199)
[INFO]  at com.android.dx.command.Main.main(Main.java:103)

What can I do to prevent this issue?

Community
  • 1
  • 1
thatidiotguy
  • 8,701
  • 13
  • 60
  • 105

1 Answers1

0

I ended up excluding the JUnit dependency in the dependent project, but I would still prefer if there were a better solution.

I will leave this open in case a better answer comes around.

thatidiotguy
  • 8,701
  • 13
  • 60
  • 105