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

AndroidAnnotations 配置指南:Android Studio 與 Eclipse 兩種環境完整設定

編輯:關於 Android 程式設計

AndroidAnnotations 用註解簡化 Activity、View、Intent 等樣板程式碼,寫起來乾淨不少。要用它,第一步是把環境配置好。

一、Android Studio 下配置

Android Studio 的配置相當輕鬆,只要動兩個 build.gradle。

1. 專案根目錄的 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)加上依賴,apt 與 api 兩件都要:

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

(4)設定 apt 參數,把產生的 AndroidManifest 交給它:

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

Build 一次專案,就完成了。

二、Eclipse 下配置

先下載 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