Gradle и Android Аннотации

Я написал файл build.gradle для своего приложения для Android. Приложение использует 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')
}

Сценарий выполняет обработку APT и генерирует классы Annotation_. Но впоследствии скрипт завершается неудачно с компиляцией import-операторов и использованием таких классов, как

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

Что не так со сценарием? Я знаю, что есть возможности для улучшения.

1 ответ

Решение

Используйте этот 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')
}

Пример сценария можно найти в руководстве или в примере проекта. Измените операторы импорта как:

import org.androidannotations.annotations.AfterViews;
Другие вопросы по тегам