3

I've seen a lot of threads about this error, but none that cover my strange scenario. First the basics:

I've got 6 projects, all of which are scaled down test projects that mimic my application's structure and which I'm using just to try to get the build working. Their dependencies are as follows:

  • exampleLib is a library that requires no other jars
    • contains Widget.java
  • exampleLib2 is a library that requires no other jars
    • contains Widget2.java
  • exampleLibNester is a library that requires exampleLib and exampleLib2
    • contains WidgetPartDeux.java
  • exampleLibNester2 is a library that requires exampleLib, exampleLib2, and exampleLibNester
    • contains WidgetPartDeux2.java
  • exampleUser is an application that requires exampleLib, exampleLib2, exampleLibNester, and exampleLibNester2
    • contains TheActivity.java
  • exampleTest is a test application that instruments exampleUser and requires exampleLib, exampleLib2, and exampleLibNester
    • contains WidgetTest.java

When I build these applications using ant locally on windows they run fine and I can use install test to run the tests. When I try to build them on my CI server, which is running linux, I get the dreaded "already added" error message.

-dex:
  [dex] Converting compiled files and external libraries into /apps/pos360/jenkins/.hudson/jobs/James-Test/exampleLibUser/bin/classes.dex...
   [dx]
   [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
   [dx] java.lang.IllegalArgumentException: already added: Lcom/example/nester/WidgetPartDeux;
   [dx]     at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
   [dx]     at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
   [dx]     at com.android.dx.command.dexer.Main.processClass(Main.java:486)
   [dx]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
   [dx]     at com.android.dx.command.dexer.Main.access$400(Main.java:67)
   [dx]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
   [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
   [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
   [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
   [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:418)
   [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
   [dx]     at com.android.dx.command.dexer.Main.run(Main.java:206)
   [dx]     at com.android.dx.command.dexer.Main.main(Main.java:174)
   [dx]     at com.android.dx.command.Main.main(Main.java:91)
   [dx]
   [dx] UNEXPECTED TOP-LEVEL EXCEPTION:
   [dx] java.lang.IllegalArgumentException: already added: Lcom/example/lib/Widget;
   [dx]     at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
   [dx]     at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
   [dx]     at com.android.dx.command.dexer.Main.processClass(Main.java:486)
   [dx]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
   [dx]     at com.android.dx.command.dexer.Main.access$400(Main.java:67)
   [dx]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
   [dx]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
   [dx]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
   [dx]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
   [dx]     at com.android.dx.command.dexer.Main.processOne(Main.java:418)
   [dx]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
   [dx]     at com.android.dx.command.dexer.Main.run(Main.java:206)
   [dx]     at com.android.dx.command.dexer.Main.main(Main.java:174)
   [dx]     at com.android.dx.command.Main.main(Main.java:91)
   [dx] 2 errors; aborting

I can look in the classes.jar files and see that exampleLibNester2 is pulling those classes into its jars, but I don't know how to prevent it from doing that nor why it does it on the linux box but not the windows one. Both SDKs have been updated to the latest version.

4

2 回答 2

0

据我了解,Android 构建的项目结构从 R14 开始发生了变化。

我建议查看您的项目构建路径并删除以 _src 结尾的所有文件夹,根据这篇文章: @foxykeep:如何修复“转换为 Dalvik 格式失败”。尽管有错误名称,但堆栈跟踪是相同的错误,并且看起来是相同的问题。

于 2012-08-02T20:35:05.570 回答
0

在库项目中构建 .jar 文件时。不要在文件 AndroidManifest.xml 上添加任何权限(纯 AndroidManifest 就足够了)。只需将您需要的所有权限添加到您的主项目清单文件中。

或者你可以简单地将你的库项目导入你的主项目而不使用 .jar。

于 2014-08-20T01:32:19.423 回答