https://github.com/excilys/androidannotations/wiki/Building-Project-Ant
Building Project Ant
Damien edited this page · 29 revisions
Pages 99
09/11/2014 The 3.2 release is out !
Using AndroidAnnotations
- Get started!
- Download
- Cookbook, full of recipes
- Customize annotation processing
- List of all available annotations
- Release Notes
- Examples
Questions?
- Read the FAQ
- Join the Mailing list
- Create an issue
- Tag on Stack Overflow
Enjoying AndroidAnnotations
Improving AndroidAnnotations
Clone this wiki locally
Clone in DesktopWhat you should know before starting
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.
Prerequisites
- This tutorial is based on the SDK v19. If you use another version, you may need to adapt this tutorial.
- if you don't already have a
build.xml
file, you can easily generate one:
android update project --path "$PROJECT_ROOT$"
How to
- Create a new folder at the root of your project (
compile-libs
would be a good candidate) and putandroidannotations-X.Y.jar
in this folder. - Put
androidannotations-X.Y-api.jar
in the$PROJECT_ROOT$/libs
- Create a
custom_rules.xml
Ant file next to yourbuild.xml
Ant script. Thebuild.xml
script generated by the Android tools automatically importscustom_rules.xml
if it exists. This enables you to customize the build, without having to modifybuild.xml
, which can therefore be easily updated. - Add properties for the generated source folder in
custom_rules.xml
<property name="generated.dir" value=".apt_generated" />
<property name="generated.absolute.dir" location="${generated.dir}" />
<property name="java.compilerargs" value="-s '${generated.absolute.dir}'" />
.apt_generated
by gen
to make the whole thing works.
- Override the
-pre-compile
target incustom_rules.xml
<target name="-pre-compile">
<mkdir dir="${generated.absolute.dir}" />
target>
- Override the
-compile
target incustom_rules.xml
- Open
$ANDROID_SDK_ROOT$/tools/ant/build.xml
- Locate the
-compile
target in this file:
- Open
<target name="-compile" depends="-build-setup, -pre-build, -code-gen, -pre-compile">
...
target>
- Copy the target and its content into
custom_rules.xml
- Modify the classpath when
javac
is invoked by adding a
node, and configure javac to generates the sources in a dedicated folder:
...
...
+
...
- You should now be able to build you project using ant:
ant clean release
Next steps
- Configure Eclipse or IntelliJ
- Start using AndroidAnnotations
Potential issues
- 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 inandroidannotations-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 moveandroidannotations-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.
- After upgrading the Android SDK, the content of$ANDROID_SDK_ROOT$/tools/ant/build.xml may have changed. Therefore, your ant build may be broken. The solution is to replace the content of the
-compile
target incustom_rules.xml
with the new-compile
target content defined in$ANDROID_SDK_ROOT$/tools/ant/build.xml
评论区