[AndroidAnnotations框架]AndroidAnnotations的配置

一、在AndroidStudio下配置androidannotations

  1. 首先,准备好你的project。

  2. AndroidStudio下的androidannotations配置是比较容易的,只需要配置两个build.gradle就可以。

  3. 配置build.gradle
    ( 1 ) 我们先配置preject目录下的build.gradle
    在buildscript> dependencies>下添加
    1
    classpath'com.neenbedankt.gradle.plugins : android-apt : 1.4'

( 2 ) 然后是配置app目录下的build.gradle
1) 在apply plugin:'com.android.application'下增加一行

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

2) 定义一个版本的常量,当前最新的版本是3.3.2

1
def AAVersion = '3.3.2'

3) 添加依赖

1
2
3
4
dependencies {
apt "org.androidannotations : androidannotations : $AAVersion"
compile "org.androidannotations : androidannotations-api : $AAVersion"
}

4) 添加apt

1
2
3
4
5
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
}
}

  1. 然后build一下project,就ok啦~

二、在eclipse下配置androidannotations

  1. 下载所需jar包。下载地址,当前最新的版本是3.3.2。解压压缩包,拿到androidannotations-api-*.jarandroidannotations-*.jar
  2. 导入jar包到工程中。androidannotations-api-*.jar放到工程的libs目录下,在工程目录下新建一个目录compile-libs,将androidannotations-*.jar放到compile-libs目录下。
  3. 配置工程。
    步骤一: Properties>Java Compiler>在Enable project specific settiongs处打勾,然后设置Compiler compliance level: 1.6

    步骤二: Properties>Java Compiler>Annotation Processing>在Enable project specific settiongs处打勾

    步骤三: Properties>Java Compiler>Annotation Processing>Factory Path>在Enable project specific settiongs处打勾,然后Add JARs->浏览工程目录,选择compile-libs目录下的androidannotations-*.jar,最后确定就可以。

  4. 然后就可以开始使用框架啦~