Making AndroidAnnotations work in IntelliJ IDEA 12

Hi, everybody!

Today I gonna write a tutorial on how to add the AndroidAnnotations library to your project in IntelliJ IDEA 12 (more specifically in IntelliJ IDEA 12.1.3).

Actually I was struggling a few hours before I made it work for the first time. And although there are quite a few posts about AndroidAnnotations + Intellij integration, still not all things were covered in those posts and so I felt a need to share my knowledge. I really hope it will help somebody 😉

OK, let’s get started! I presume you already have Intellij IDEA installed. If not, get it done!
We will need an Android project to test the annotations, so you need to create one. It can be a Hello world! or something like that 😉

The next thing is the AndroidAnnotations library itself. You can download a .zip bundle on this page – by clicking on Download AndroidAnnotations 2.7.1. Extract an androidannotations-api-2.7.1.jar and put it into your project’s libs directory. Also, extract an androidannotations-2.7.1.jar and put in into compile-libs directory.

Now, don’t get confused! Add androidannotations-api-2.7.1.jar to the project’s modules. See the screenshot below. AndroidAnnotations jar

Next, go to File -> Settings -> Compiler -> Annotation Processors. Make sure your settings look like on the screenshot below. Please pay attention as the path is pointing to you_project_pathcompile-libsandroidannotations-2.7.1.jar !!!

AndroidAnnotations annotation processors

Now add some AndroidAnnotations specific code. I just copy and pasted the one from here. Be sure your Activity has an _ suffix in AndroidManifest.xml and in a Launch path.

Your project’s configuration should look like this:

AndroidAnnotations main activity

Now rebuild your project (Build -> Rebuild Project) and Run it!

Don’t worry about warnings. If you have done everything described above you should see a Hello World! activity on your phone/emulator screen.

If you haven’t succeeded, write a comment here – I will try to help you 😉 Happy coding!

!!! UPDATE !!!

As you know, while using the AndroidAnnotations library one must write ActivityName + _ suffix in intents for example. Like this:

startActivity(this, MyListActivity_.class);

And this MyListActivity_ will be underlined with red and you will get an error that no such class exists. In order to not have such errors, you only need to add the generated folder to sources. This is done via Project Structure -> Modules -> Sources tab -> right click on generated folder -> Sources. Like this:

AndroidAnnotations gen folder

And that’s it! From now on you won’t get errors when using a _ suffix in your code. Enjoy! 😉

Like and share:

Published by

Tonia Tkachuk

I'm an Android Developer, writing code for living and for fun. Love beautiful apps with a clean code inside. Enjoy travelling and reading.

Leave a Reply

Your email address will not be published.