Building Project Gradle - shiraji/androidannotations GitHub Wiki

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

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

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

        // 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
    }
}

Snapshots

###Setup

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 = 'https://oss.sonatype.org/content/repositories/snapshots'
    }
}

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"
}

###Update 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.

####Example 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