Share & Follow

Get new posts when they come!

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 – https://github.com/excilys/androidannotations/wiki/Download 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.

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:

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:

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.
View all posts by Tonia Tkachuk