Building Project Gradle - yDelouis/androidannotations GitHub Wiki

Annotation processor Gradle plugin

Preferred way

You can use the android-apt Gradle plugin to launch AndroidAnnotation processing.

Here is a quick working sample:

buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath 'com.android.tools.build:gradle:0.11.+'
        // Since Android's Gradle plugin 0.11, you have to use android-apt >= 1.3
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

apply plugin: 'android'
apply plugin: 'android-apt'
def AAVersion = 'XXX'

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile 
        resourcePackageName 'com.myproject.package'

        // If you're using Android NBS flavors you should use the following line instead of hard-coded packageName
        // resourcePackageName android.defaultConfig.packageName

        // You can set optional annotation processing options here, like these commented options:
        // logLevel 'INFO'
        // logFile '/var/log/aa.log'
    }
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
    }

    // This is only needed if you project structure doesn't fit the one found here
    // http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Project-Structure
    sourceSets {
        main {
            // manifest.srcFile 'src/main/AndroidManifest.xml'
            // java.srcDirs = ['src/main/java', 'build/generated/source/apt/${variant.dirName}']
            // resources.srcDirs = ['src/main/resources']
            // res.srcDirs = ['src/main/res']
            // assets.srcDirs = ['src/main/assets']
        }
    }
}

Note: Don't forget to adjust android.sourceSets.main configuration to fit your needs if necesseray. For example, in IntelliJ source files are in src/main folder while in Eclipse there are in src folder. You should also specify the folder where the generated classes will be written.

AndroidAnnotations Gradle plugin

Deprecated

There is also a Gradle AndroidAnnotations Plugin to use AndroidAnnotations in Gradle project. This plugin generates output files based on annotations on compile; it also configures IDEA projects to use AndroidAnnotations.

Unfortunately this plugin seems to not be maintained anymore.

Instructions can be found in the plugin wiki.