-
Notifications
You must be signed in to change notification settings - Fork 0
Building Project Ant
AndroidAnnotations works by generating code at compile time.
AndroidAnnotations provides two jars:
-
androidannotations-X.Y.jar is needed to generate the code at compile time. There is no reason to keep this jar at runtime because:
- Its code will never be executed at runtime.
- It makes your APK size bigger than needed.
- 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.
-
if you don't already have a build.xml, you can easily generate it:
android update project --path "$PROJECT_ROOT$"-
Create a new folder at the root of your project (compile-libs would 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 encounter the following error:
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.
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 file away from the $PROJECT_ROOT$/libs folder.
- Anything else ? Contact us on the mailing list, or create an issue, and we'll try to help you.
03/30/2012 The 2.5.1 release is out
- Get started!
- Cookbook, full of recipes
- Examples
- Read the FAQ
- Join the Mailing list
- Create an issue