Skip to content

Building Project Gradle

Csaba Kozák edited this page Mar 15, 2016 · 26 revisions

15/03/2016 The 4.0.0 release is out !

Using AndroidAnnotations


Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally

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

Here is a quick working sample:

buildscript {
    repositories {
    dependencies {
        // replace with the current version of the Android plugin
        classpath ''
        // replace with the current version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

repositories {

apply plugin: ''
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

        // you should set your package name here if you are using different application IDs
        // resourcePackageName ""

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 23

Adding more AA plugins

If you are using more AA plugins, you must declare additional dependencies:

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

Substitute {plugin-name} with the real name of the plugin what you want to add.



If you want to use snapshot versions of AndroidAnnotations, you should configure your project with the snapshot repository.

Add this to your build.gradle file to access snapshots repo:

repositories {
    maven {
        url = ''

Then, under def AAVersion = 'XXX', add snapshot version this way:

def AAVersion = 'XXX'
def AASnapshotVersion = 'XXX-SNAPSHOT'

with XXX being the snapshot version. For 4.0 snapshot version, it would be:

def AASnapshotVersion = '4.0-SNAPSHOT'

Finally, in dependencies, where you use $AAVersion, use $AASnapshotVersion instead:

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


Unlike release builds, where changing the version number to the next will make gradle fetch the new version on while building or assembling, snapshots keep the same version number, and are consequently not updated by gradle.

Thankfully, there's a way to force gradle to update snapshots, but it may take some time, or a while, depending of your connection and the size of the downloaded dependencies. Therefore, you shouldn't run the command below if the current snapshot is already up to date (you can check the recent commits on this repo), or if there's minor changes which don't impact you.

To perform the update, open a terminal in your root project's dir and add the --refresh-dependencies flag to any build gradle command.


As you are using a snapshot version, you are probably building a debug apk, so you can type:

./gradlew assembleDebug --refresh-dependencies

to assemble all your modules and update your project's dependencies, which should include AA's snapshot.

Next step

Something went wrong with that request. Please try again.