Gradle build file for a project with Android Annotations

No comments on Gradle build file for a project with Android Annotations

Written by

in

There is a sample Gradle build file for a project with Android Annotations. This is pretty complicated stuff, that was achieved with a lot of my blood, so I decided to post it here, so that you can use it to try to find your mistakes. Android Annotations library is loaded with apt. The position of every setting is important. There is also a trick to avoid Lint errors and a custom task to run app via command line.

I used Gradle 1.12 and Android Studio 0.8.4 with Android SDK 20, Android Build Tools 20.0 and Android Plugin 0.12.+.

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.3'
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

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

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile "com.android.support:support-v4:18.0.+"
    compile "com.android.support:appcompat-v7:18.0.+"
    compile 'org.apache.commons:commons-lang3:3.0.+'
    compile fileTree(dir: 'libs', include: '*.jar')
}

apt {
    arguments {
        androidManifestFile variant.processResources.manifestFile
        resourcePackageName "ru.rabota.app2"
    }
}

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 20
        versionCode 17
        versionName "2.4.2"
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        androidTest.setRoot('tests')
    }

    lintOptions {
        abortOnError false
    }
}

task appStart(type: Exec, dependsOn: ':installDebug') {
    // linux 
    commandLine 'adb', 'shell', 'am', 'start', '-n', 'ru.rabota.app2/ru.rabota.intro.IntroActivity'

    // windows
    // commandLine 'cmd', '/c', 'adb', 'shell', 'am', 'start', '-n', 'com.alwawee.multiverse/com.alwawee.main.MainActivity'      
}

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *