AndroidAnnotations setup in Android Studio (beta)

**** UPDATE: A new post describes the AndroidAnnotations setup in Android Studio 1.0.2 ****

This is a small follow-up on the post Making AndroidAnnotations work with IntelliJ IDEA, but this time focusing on Android Studio and the Gradle build system. Fortunately things are a bit easier now, using the android-apt Gradle plugin, and there are some instructions at the Android Annotations wiki. However, I ran into some problems setting it up and therefore thought that a simple step-by-step guide perhaps could help someone else trying to do the same thing. Here is what I did in order to get things running with a project created in Android Studio (version 0.4.6).

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 add a dependency to android-apt.

Step 2
Then apply the android-apt plugin by adding this line below the one that applies the android plugin. Note that the order here is important!

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

Step 4
Finally add dependencies to AndroidAnnotations.

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

Step 5
Do a sync and your project should build and run fine! Now you are all set to start using AndroidAnnotations. And when you do, don’t forget to add that underscore to your Activity in the manifest!

This Post Has 18 Comments

  1. With intellij 13 you need the

    classpath ‘com.android.tools.build:gradle:0.9.+’w

    in the dependencies for the buildscript to.

  2. I’ve an error “cannot find symbol class” for the class SharedData_ that I reference in my code because with the annotation @Pref you must use the generated class.
    Have some one used the @Pref annotation in Android Studio?

  3. Nice, though the Android plugin has the ‘provided’ keyword so all I have to do is do:

    dependencies {

    provided ‘com.googlecode.androidannotations:androidannotations:2.7.1’
    compile ‘com.googlecode.androidannotations:androidannotations-api:2.7.1’

    }

    No need for the apt plugin.

    I’m using gradle plugin 0.9.+

  4. Very nice, works out of the box on Android Studio 0.5.7

    Thanks

  5. thanks,I was successful! works out of the box on Android Studio 0.5.8

  6. I followed every step and it worked nicely on Androidstudio 0.5.8 ! thank’s !

  7. Great article. Thanks so much! My build script looks something like this for Android Studio 0.5.2.

    If the AndroidManifest entries for activities seem to generate errors, then build Make Module will solve the problem!

    buildscript {
    repositories {
    mavenCentral()
    }
    dependencies {
    classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.2+’
    }
    }

    apply plugin: ‘android’
    apply plugin: ‘android-apt’

    repositories() {
    mavenCentral()
    }

    dependencies {
    apt “org.androidannotations:androidannotations:3.0+”
    compile “org.androidannotations:androidannotations-api:3.0+”
    compile ‘com.android.support:appcompat-v7:19.1.0’
    compile fileTree(dir: ‘libs’, include: ‘*.jar’)
    compile ‘de.greenrobot:eventbus:2.2.0’
    }

    android {
    .
    .
    .
    }

    apt {
    arguments {
    androidManifestFile variant.processResources.manifestFile
    resourcePackageName “com.mycompany.package”
    }
    }

  8. I had to add

    configurations {
    apt
    }

    for this to work.

  9. To get it to work with the latest Android Studio 0.8.2 and Gradle 0.12. I had to enable annotation processing first in /.idea/compiler.xml:

  10. Please, update this tutorial, is not working anymore :(

  11. Still does not work for me. I get the following error:
    Error:Artifact ‘com.android.support:support-annotations:20.0.0:support-annotations.jar’ not found.
    Using sdk 20.0 and gradle 0.12+

  12. Error:Execution failed for task ‘:app:processDebugManifest’.
    > Manifest merger failed : uses-sdk:minSdkVersion 15 cannot be smaller than version L declared in library com.android.support:appcompat-v7:21.0.0-rc1

    That’s it. Android Studio 0.8.9.

  13. For AndroidStudio newbies like me, don’t forget to build after the gradle configuration. Otherwise there will be an error in the manifest file for “cannot resolve symbol com.yourpackage.MainActivity_ “.

  14. I have some problem in Android studio. Should I upgrade it?

  15. Not able to implement in android studio 3.+ version. Kindly help.

Leave a Reply

Close Menu