AndroidAnnotations setup in Android Studio

This is a small follow-up on the post AndroidAnnotations setup in Android Studio (beta) now that Android Studio is no longer in beta. Not much about this step-by-step guide has changed but since there were people having problems getting everything to work I decided to post an updated version. This is what I did in order to get things running with a new project created in Android Studio (version 1.0.2).

The file we are going to modify is the build.gradle file located in the app folder of your project, not the one found in the root.

Step 1
First we need to apply the android-apt plugin and add a dependency to it. Be sure to add this below the line that applies the android plugin. Note that the order here is important!

Step 2

Now hand it the following arguments. Remember to replace com.example.package.name with the correct package name for your project.

Step 3
Finally add dependencies to AndroidAnnotations.

The contents of app/build.gradle should now look something like this.

Step 4
Now rebuild your project and it should run fine! Now you are all set to start using AndroidAnnotations. And when you do, don’t forget to add that underscore to your Activities in the manifest!

This Post Has 9 Comments

  1. Hi Hannes,

    I’m having some trouble with this.

    1. How do I install the apt plugin? Does adding “apply plugin…” enough on its own?
    2. Where should the annotations jars live? I’m currently getting ‘could not find org.androidannotations…’.

    I’m using Android Studio 1.0.2, and trying to use AA 2.7.1. I’m currently trying to get it to work on a fresh project so that I can figure out what is going wrong in an existing project I’m trying to migrate to Android Studio. I can upgrade AA to 3+ if I need to, but would prefer to not have to yet.

    Thanks!
    Karl

    1. Hi Karl,

      1. Yeah that should be enough as long as you also apply the com.android.application plugin and have the buildscript dependency set.
      2. I think the jar file ends up in the .m2 folder in the user catalog, you should not have to add it yourself.

      It seems that aa 2.7.1 is not found on the repository, weird…

  2. So great!. Thank so much.

  3. You’re awesome, thanks for this awesome detailed breakdown. Really helped :)

  4. hello thanks for this tutorial. just one question, how important is this line:
    apt {
    arguments {
    androidManifestFile variant.outputs[0].processResources.manifestFile
    resourcePackageName ‘com.example.raymund.rvamobile’
    }
    }

    or what does it actually do?
    currently, i’ve been having problems with integrating Realm since the line:
    androidManifestFile variant.outputs[0].processResources.manifestFile
    is always throwing error once i added Realm’s classpath or plugin.

    Thanks for the help in advance :)

  5. Hi Hannes,

    Getting Error:(44, 0) Could not find method miniyEnabled() for arguments [false]

Leave a Reply

Close Menu