Skip to content

Building Project Gradle

Heath Borders edited this page Jan 31, 2014 · 6 revisions

Annotation processor Gradle plugin

You can use the android-apt Gradle plugin to launch AndroidAnnotation processing. A quick example of how to use it is included below. A full example project with a library project that also uses Android Annotations exists as well.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath 'com.android.tools.build:gradle:0.7.3+'
        // the latest version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
    }
}

apply plugin: 'android'
apply plugin: 'android-apt'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile

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

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

dependencies {
    apt "org.androidannotations:androidannotations:3.0+"
    compile "org.androidannotations:androidannotations-api:3.0+"
}

AndroidAnnotations Gradle plugin

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.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally