excilys/androidannotations — Issue #22: AndroidAnnotations JAR should not have same classes in API JAR
Author: pyricau
Created: 2012-01-06 11:07:47+00:00
State: open

@ealden, Dec 12, 2011
When combining both the full JAR and the API JAR, I get an error saying that some classes have already been loaded. This is because the full JAR is a superset of the API JAR, hence they can't be combined together.

While only the API JAR should be included in Android projects, setting up build systems such as Gradle is a bit more complicated as it is not possible to define both JARs as dependencies and as part of the classpath. For Gradle, I had to resort to including the full JAR as part of the project, and referencing it in the configuration.

It would be easier really if the full JAR needed the API JAR to work completely, as all the API JAR-specific classes are not duplicated. I'm not fully aware of the decisions with AndroidAnnotations early on, so this might be a moot point.

@pyricau, Dec 15, 2011
I think you have a good point here. My main concern is that many of our users don't use Maven in their Android projects, so it's not easy for them to deal with dependencies, and I'd rather not ask them to add multiple jar to their annotation processing classpath.

I'm starting to think that maybe we should have 3 main artifact instead of 2 :

androidannotations-full (contains core, api and code model) : for non maven users
androidannotations (contains core, depends on api and code model) : for maven users
androidannotations-api (no dependencies) : runtime jar, for both maven and non maven users

What do you think ?

@ealden, Dec 15, 2011
Yes I think that makes sense. Should be much easier to add this at least for Gradle.
Delete comment Comment 3 by project member py.ricau, Dec 29, 2011
Funny enough, I'm starting to have the same error when using android-maven-plugin 3.0.0 (previously I used 3.0.0 -alpha-13).

[INFO] --- android-maven-plugin:3.0.0:dex (default-dex) @ functional-test-1-5 ---
[INFO] /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java [-Xmx512m, -jar, /Users/pyricau/bin/android-sdk-mac_x86/platform-tools/lib/dx.jar, --dex, --output=/Users/pyricau/Projets/remote/androidannotations/AndroidAnnotations/functional-test-1-5/target/classes.dex, /Users/pyricau/.m2/repository/com/google/inject/guice/2.0-no_aop/guice-2.0-no_aop.jar, /Users/pyricau/.m2/repository/com/googlecode/androidannotations/androidannotations/2.3-SNAPSHOT/androidannotations-2.3-SNAPSHOT.jar, /Users/pyricau/.m2/repository/org/roboguice/roboguice/1.1.2/roboguice-1.1.2.jar, /Users/pyricau/Projets/remote/androidannotations/AndroidAnnotations/functional-test-1-5/target/classes, /Users/pyricau/.m2/repository/com/sun/codemodel/codemodel/2.4.1/codemodel-2.4.1.jar, /Users/pyricau/.m2/repository/com/googlecode/androidannotations/androidannotations/2.3-SNAPSHOT/androidannotations-2.3-SNAPSHOT-api.jar]
[INFO]
[INFO] UNEXPECTED TOP-LEVEL EXCEPTION:
[INFO] java.lang.IllegalArgumentException: already added: Lcom/googlecode/androidannotations/annotations/AfterViews;
[INFO]	at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[INFO]	at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[INFO]	at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[INFO]	at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[INFO]	at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[INFO]	at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[INFO]	at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[INFO]	at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[INFO]	at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[INFO]	at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[INFO]	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[INFO]	at com.android.dx.command.dexer.Main.run(Main.java:206)
[INFO]	at com.android.dx.command.dexer.Main.main(Main.java:174)
[INFO]	at com.android.dx.command.Main.main(Main.java:95)

@pyricau Dec 30, 2011
However, I was able to fix that by using scope "provided" instead of "compile" for artifact androidannotations.

I should go read more about maven scopes...