Skip to content

Building Project Gradle

WonderCsabo edited this page Dec 9, 2014 · 13 revisions

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:1.0.0'
        // replace with the current version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = 'XXX'

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

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        // if you have multiple outputs (when using splits), you may want to have other index than 0

        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 "20.0.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 necessary. 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.

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Clone this wiki locally