excilys/androidannotations — Issue #23: AfterViews causes cmd line build to fail.
Author: pyricau
Created: 2012-01-06 15:51:16+00:00
State: open

@johngray1965, Dec 28, 2011
What steps will reproduce the problem?
1. android update project --path .
2. ant debug

What is the expected output?
A successful ant build.

What do you see instead?
An error in the packaging:
java.lang.IllegalArgumentException: already added: Lcom/googlecode/androidannotations/annotations/AfterViews;

I thinks AfterViews has been included twice.

What version of AndroidAnnotations are you using?
2.2

On what operating system?
Both Win7 and Ubuntu

I see this consistently across several projects that build fine in Eclipse, and build fine on the cmd line if we remove androidannotations.

This really makes it hard to use androidannotations with an automated build.

************************

@matboniface, Dec 28, 2011
This error is thrown by dx command when two classes with the same name and package name are detected.

Have you placed both the androidannotations-X.Y.jar and androidannotations-X.Y-api.jar in the "libs" folder of your project ?

All the jars installed in the "libs" folder are directly passed to the dx command, and so, they are packaged in dex format in your apk file. This is not good because a lot of code that is not used at runtime is embedded in your apk .

The only (relatively acceptable) workaround I found is :
- Remove androidannotations-X.Y.jar from the "libs" folder (let the androidannotations-X.Y-api.jar in this folder) and install it in another folder ("compile-libs" for this example)
- Override the "-compile" target of the imported ant build file by copying it from the $ANDROID_SDK$/tools/ant/build.xml to your $PROJECT_ROOT$/build.xml
- add the content of "compile-libs" to the classpath when is invoked (in the "-compile" target of your $PROJECT_ROOT$/build.xml) :
```

...

...

```

You're right, working with ant + android + androidannotations is not easy at the moment, we are working on the documentation for automated builds.