Mike Weiss
Mike Weiss

Reputation: 13

Gradle and AndroidAnnotations

I have written a build.gradle file for my Android App. The App uses AndroidAnnotations.

apply plugin: 'com.android.application'
apply plugin: 'android-apt'

def AAVersion = '3.3.2'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'org.androidannotations:androidannotations:3.3.2'
    }
}

configurations {
    apt
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName "de.xxx"
    }
}

android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "de.xxx"
        minSdkVersion 11
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard.cfg'
        }
    }
}

repositories {
    jcenter()
    mavenCentral()
    mavenLocal()
}

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:23.1.1'
    compile files('libs/acra-4.3.0.jar')
}

The script does the APT profecessing and generates the Annotation_ classes. But afterwards the script fails with compilation of import-Statements and usages of classes like

import com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EFragment;
import com.googlecode.androidannotations.annotations.ViewById;

Whats wrong with the script? I know there is room for improvement.

Upvotes: 0

Views: 2584

Answers (1)

WonderCsabo
WonderCsabo

Reputation: 12207

Use this build.gradle :

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

def AAVersion = '3.3.2'

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        mavenLocal()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

apt {
    arguments {
        androidManifestFile variant.outputs[0]?.processResources?.manifestFile
        resourcePackageName "de.xxx"
    }
}

android {
    compileSdkVersion 'Google Inc.:Google APIs:23'
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "de.xxx"
        minSdkVersion 11
        targetSdkVersion 23
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard.cfg'
        }
    }
}

repositories {
    jcenter()
    mavenCentral()
    mavenLocal()
}

dependencies {
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:23.1.1'
    compile files('libs/acra-4.3.0.jar')
}

The example script can be found in the guide, or in the sample project. Change the import statements like:

import org.androidannotations.annotations.AfterViews;

Upvotes: 1

Related Questions