Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

AndroidAnnotations 框架的配置詳解

編輯:關於 Android 開發

AndroidAnnotations 框架的配置詳解

一、在 Android Studio 下配置 AndroidAnnotations

首先準備好你的專案。Android Studio 下的配置相對簡單,只需修改兩個 build.gradle。

配置 build.gradle:

(1) 先配置 project 目錄下的 build.gradle,在 buildscript > dependencies 下添加:

 classpath 'com.neenbedankt.gradle.plugins : android-apt : 1.4'

(2) 然後配置 app 目錄下的 build.gradle:

1) 在 apply plugin:'com.android.application' 下增加一行:

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

2) 定義版本常量(當前最新為 3.3.2):

 def AAVersion = '3.3.2'

3) 添加依賴:

 dependencies { apt "org.androidannotations : androidannotations : $AAVersion" compile "org.androidannotations : androidannotations-api : $AAVersion" }

4) 添加 apt:

 apt { arguments { androidManifestFile variant.outputs[0].processResources.manifestFile } }

然後 build 一下專案即可。

二、在 Eclipse 下配置 AndroidAnnotations

下載所需 jar 包(當前最新為 3.3.2),解壓後拿到 androidannotations-api-*.jar 和 androidannotations-*.jar。把 androidannotations-api-*.jar 放到工程的 libs 目錄下,在工程目錄下新建 compile-libs 目錄並放入 androidannotations-*.jar。

步驟一: Properties > Java Compiler > 在 Enable project specific settings 處打勾,並設置 Compiler compliance level 為 1.6。

步驟二: Properties > Java Compiler > Annotation Processing > 在 Enable project specific settings 處打勾。

步驟三: Properties > Java Compiler > Annotation Processing > Factory Path > 在 Enable project specific settings 處打勾,然後 Add JARs,瀏覽工程目錄,選擇 compile-libs 目錄下的 androidannotations-*.jar,最後確定即可。

完成以上配置後,就可以開始使用這個框架了。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved