Gradle 和 AndroidAnnotations

Gradle and AndroidAnnotations

我已经为我的 Android 应用程序编写了一个 build.gradle 文件。该应用程序使用 Android 注释。

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 com.googlecode.androidannotations.annotations.AfterViews;
import com.googlecode.androidannotations.annotations.EFragment;
import com.googlecode.androidannotations.annotations.ViewById;

脚本有什么问题吗?我知道还有改进的余地。

使用这个 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')
}

示例脚本可以在 guide, or in the sample project 中找到。 更改导入语句,例如:

import org.androidannotations.annotations.AfterViews;