Android class “already added” when building

Posted by admin on Mar 22, 2012 in Uncategorized |

I am working on an Android project constructed of:

  • The main app (very lightweight wrapper + AndroidManifest.xml)
  • The main library (where all the real work gets done)
  • Facebook-android-sdk
  • HockeySDK-Android

Recently, I started seeing the following error when building the app using ant:

[dx] UNEXPECTED TOP-LEVEL EXCEPTION:
[dx] java.lang.IllegalArgumentException: already added: Lcom/facebook/android/R$anim;
[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:95)
[dx] 1 error; aborting
Upon inspection, it appeared that there were multiple R.java files per module with different package names but the same content. Removing all the “gen” directories in the entire project resulted in a successful from the command line.

Comments are closed.

Copyright © 2017 Standalone Code LLC All rights reserved. Theme by Laptop Geek.