Skip to content
This repository has been archived by the owner on Feb 26, 2023. It is now read-only.

Building Project Gradle

Csaba Kozák edited this page Sep 16, 2019 · 31 revisions

Starting with version 2.3.0 the Android Plugin has built-in support for annotation processors. If you require to use an older version of the plugin you can find an older version of this page explaining the use of android-apt plugin here.

Here is a working sample for Android Plugin 3.4.0:

buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath 'com.android.tools.build:gradle:3.4.0'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

apply plugin: 'com.android.application'

def AAVersion = 'XXX'
dependencies {
    annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29

        // If you have different applicationIds for buildTypes or productFlavors uncomment this block.
        //javaCompileOptions {
        //    annotationProcessorOptions {
        //        arguments = ["resourcePackageName": android.defaultConfig.applicationId]
        //    }
        //}
    }
}

Adding more AA plugins

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

dependencies {
    annotationProcessor "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.

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.7.0 snapshot version, it would be:

def AASnapshotVersion = '4.7.0-SNAPSHOT'

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

dependencies {
    annotationProcessor "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

Using AndroidAnnotations

Questions?

Enjoying AndroidAnnotations

Improving AndroidAnnotations

Extending AndroidAnnotations

Clone this wiki locally