-
Notifications
You must be signed in to change notification settings - Fork 0
Building Project Ant
AndroidAnnotations works by generating code at compile time. In fact it uses an Annotation Processor.
AndroidAnnotations provides you two jars :
-
androidannotations-X.Y.jar contains the code to generate the code at compile time. There is no reason to keep this jar at runtime because :
-
This code will never be executed at runtime.
-
This jar make your apk size bigger than needed. (near 250kb)
-
-
androidannotations-X.Y-api.jar only contains the code you need at runtime.
-
This tutorial is based on the SDK v16. If you are using an other version, you will certainly need to adapt this tutorial.
-
We suppose you have already a build.xml, if not you can easily generate it :
android update project --path="$PROJECT_ROOT$"-
Create a folder at the root of your project ("compile-libs" seems to be a good candidate) and put the androidannotations-X.Y.jar in this folder.
-
Put the androidannotations-X.Y-api.jar in the
$PROJECT_ROOT$ /libs -
Override the -compile target defined in the imported ant script in your build.xml :
-
Open the
$ANDROID_SDK_ROOT$ /tools/ant/build.xml file -
Locate the -compile defined target in this file, something like that :
-
<target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">
...
</target>- Copy the target and his content into your own build.xml before this statement
<import file="${sdk.dir}/tools/ant/build.xml">- Modify the classpath when javac is invoked by adding a fileset :
<javac ... >
...
<classpath>
...
<fileset dir="compile-libs" includes="*.jar"/>
</classpath>
...
</javac>- At this time, you should be able to build you project using ant :
ant release- If you put the two AndroidAnnotations jars in the
$PROJECT_ROOT$ /libs you will certainly obtain this result :
java.lang.IllegalArgumentException: already added: Lcom/googlecode/androidannotations/annotations/AfterViews;
androidannotations-X.Y-api.jar is a subset of androidannotations-X.Y.jar. So each class in androidannotations-X.Y-api.jar is present in androidannotations-X.Y.jar. In our case, this error is thrown when the dx command is invoked and two classes with the same name and package name are detected. To prevent this error you have to move androidannotations-X.Y.jar from the $PROJECT_ROOT$/libs folder to another folder.
- Contact us using the mailing list, we'll try to help you.
14/06/2012 The 2.6 release is out
- Get started!
- Cookbook, full of recipes
- List of all available annotations
- Release Notes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow