Search code examples
javaandroidgradleandroid-studioandroid-annotations

How to attach android annotations v3+


I know that similar topics exists, but actually none of them works at 100%.

Kind of hints/script how to attach those latest android annotations to latest android studio version.

Env: Ubuntu x64, gradle 2.0, android studio 0.8.2

Regards

Edit: The solution also works with AndroidStudio 1.0 .


Solution

  • I use Android Studio 0.8.14.

    My build.gradle for main 'app' module looks like:

    apply plugin: 'com.android.application'
    apply plugin: 'android-apt'
    
    String packageName = "mateuszklimek.aaexample"
    
    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.1"
    
        defaultConfig {
            applicationId packageName
            minSdkVersion 15
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
    }
    
    apt {
        arguments {
            androidManifestFile variant.processResources.manifestFile
            resourcePackageName packageName
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        apt "org.androidannotations:androidannotations:3.2"
        compile "org.androidannotations:androidannotations-api:3.2"
    }
    

    Don't forget about configure top-level build.gradle:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.13.2'
            classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    


    I have pushed example projet to Github.
    You can build it in console by gradlew assembleDebug.