Be-Bound AndroidAnnotations

Set Up AndroidAnnotations

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

This article will briefly explain how to setup AndroidAnnotations in an existing project to simplify your code. For more details, you can check the official git repository wiki

Why Use AndroidAnnotations

AndroidAnnotations will considerably reduce the time you spend developing as well as the boilerplate code you need to write. Moreover, with some cool features as annotations for events, it’ll offset the fact that we can’t use lambda (at least without a tool like retrolambda) in android development.

Step 1: apt plugin

First, you need to add the apt plugin to your classpath, this plugin can be used for a lot of library using annotation processing, it’ll take care of configuring everything for your build. If you want more details, check the official website 

Add the following classpath line to your project root build.gradle file

Now, apply the plugin in your module’s build.gradle

Step 2: setup AndroidAnnotations

Configure annotation processor

To setup AndroidAnnotations, you first need to pass arguments to the annotation processor, add the following code to the end of your module’s build.gradle

Add dependency

Define a constant below the apply lines in your build.gradle file:

You can now add the dependency in your block:

You’re done! You can now start using AndroidAnnotations. For more examples and explanations, I recommend reading the documentation at https://github.com/excilys/androidannotations/wiki

Important note

The first time you want to build and run your project (can also be the case after a clean ), you’ll need to make your project, it’ll run the annotation processing. I had a hard time figuring this the first time, I couldn’t run my project, and impossible to start the annotation processor manually.

The versions I used for the library and the apt plugin are the current latest version, but you’ll want to check the current latest version when you read this article.


Leave a Reply