Sebastian
Sebastian

Reputation: 226

Build project containing lib project containing lib project with ant

We have a project structure like following:

sharedlib (lib-project, containing classes, that are useful in many apps)
-> main-project (lib-project, containing everything to run the app)
---> 2 branded projects (with different icons/styles for the main-project)

In Eclipse the main project is a library project, referencing the sharelibs in Android Settings and the two branded projects reference the main project as library.

If we compile the branded projects under Eclipse everything works fine, but we could not get ant build (sdk tools r16) to work. We tried several variants for adding the library projects into the branded projects. We got either an error, that the class files of the library project can't be found or the following dex error:

-dex:
 [echo] Converting compiled files and external libraries into .../bin/classes.dex...
[apply] 
[apply] UNEXPECTED TOP-LEVEL EXCEPTION:
[apply] java.lang.IllegalArgumentException: already added: L.../android/android/lib/R$attr;
[apply]     at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[apply]     at com.android.dx.dex.file.DexFile.add(DexFile.java:143)
[apply]     at com.android.dx.command.dexer.Main.processClass(Main.java:372)
[apply]     at com.android.dx.command.dexer.Main.processFileBytes(Main.java:346)
[apply]     at com.android.dx.command.dexer.Main.access$400(Main.java:59)
[apply]     at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:294)
[apply]     at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:244)
[apply]     at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:130)
[apply]     at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:108)
[apply]     at com.android.dx.command.dexer.Main.processOne(Main.java:313)
[apply]     at com.android.dx.command.dexer.Main.processAllFiles(Main.java:233)
[apply]     at com.android.dx.command.dexer.Main.run(Main.java:185)
[apply]     at com.android.dx.command.dexer.Main.main(Main.java:166)
[apply]     at com.android.dx.command.Main.main(Main.java:90)
[apply] 1 error; aborting

So the problem is either that our library isn't added at all or added twice. Any ideas, how the ant build file has to look to build the branded projects?

Upvotes: 1

Views: 1251

Answers (1)

Jomoos
Jomoos

Reputation: 13083

I also ran in to same error and a Google search has taken me to the following link, and it solves my problem.

Davlik bug? UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: [classXXX]

Following is the explanation to the problem, taken from the link:

The (admittedly ugly) message is trying to tell you that you have in
fact managed to include two classes with the same fully-qualified name
(package + name) in your dx commandline. If you are using dx
implicitly via the Eclipse plugin (looks like you are), then you have
somehow managed to add the same classes twice in the Eclipse UI. 

Here, you may have added the class L.../android/android/lib/R twice in your classpath. It seems that two or more version of autogenerated class R with the same package name is in your classpath. Check both the application and libraries to make sure that the class R has placed under different package in all of them.

Hope this helps :)

Upvotes: 3

Related Questions