java.lang.IllegalArgumentException:已添加:Lorg / hamcrest / BaseDescription;

时间:2014-04-15 21:39:05

标签: java android maven

因此,当您包含JUnit 4.10时,我知道在简单情况下描述错误的页面:

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

不幸的是,我使用的是一个依赖于JUnit的库:

com.googlecode.json-简单:JSON-简单:罐:1.1.1

所以我无法添加排除。这是依赖树:

[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

这是maven错误:

[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)

如何防止此问题?

1 个答案:

答案 0 :(得分:0)

我最终在依赖项目中排除了JUnit依赖项,但如果有更好的解决方案,我仍然会更喜欢。

如果有更好的答案,我会保持开放状态。