1.引入对android-apt的依赖。在全局build.gradle中文件中添加以下代码。(Project目录下的build.gradle)

repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
}
}

2.设置android-apt参数 。注意把包名换成你的应用的。另外outputs[0]是在新的android-studio的版本中才需要加的。(Module目录下的build.gradle)


apply plugin: 'android-apt'  //添加android-apt插件

apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
//androidManifestFile variant.processResources.manifestFile(老版本写法)
resourcePackageName "你的包名"
}
}

3.使用apt引入对androidannotation的依赖。(Module目录下的build.gradle)

dependencies {
apt 'org.androidannotations:androidannotations:3.2'
compile 'org.androidannotations:androidannotations-api:3.2' }

4.最后的build文件应该是这样的。

// Project目录下的build.gradle

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
}
} //Module目录下的build.gradle apply plugin: 'com.android.application'
apply plugin: 'android-apt' android {
compileSdkVersion 21
buildToolsVersion 21.1.2 defaultConfig {
applicationId com.tanglikang.annotationtest
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName 1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
} apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName com.tanglikang.annotationtest
}
} dependencies {
apt org.androidannotations:androidannotations:3.0+ // add these
compile org.androidannotations:androidannotations-api:3.0+ // two lines
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}

5.重新build工程,系统会自动下载依赖的第三方库。然后就可以使用AndroidAnnotation了。

注:如果出现下列错误,请将dependencies中的“compile fileTree(dir: 'libs', include: ['*.jar'])”删除。

Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/androidannotations/annotations/AfterExtras;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:)
at com.android.dx.command.dexer.Main.run(Main.java:)
at com.android.dx.command.dexer.Main.main(Main.java:)
at com.android.dx.command.Main.main(Main.java:)

AndroidAnnotations配置--Android studio的更多相关文章

  1. Ubuntu环境下配置Android Studio【转】

    本文转载自:https://www.jianshu.com/p/1f6295f9c955 之前学习Android开发的时候,一直跟各种教程一样,使用的是Eclipse+ADT,主要是比较方便,容易上手 ...

  2. 安装并配置 Android Studio 开发工具和 Genymotion 模拟器

    需求说明: 安装并配置 Android Studio 开发工具和 Genymotion 模拟器. 熟练使用 Genymotion 模拟器,掌握 Genymotion 模拟器的基本设置和程序安装. 实现 ...

  3. 0.[WP Developer体验Andriod开发]之从零安装配置Android Studio并编写第一个Android App

    0. 所需的安装文件 笔者做了几年WP,近来对Android有点兴趣,尝试一下Android开发,废话不多说,直接进入主题,先安装开发环境,笔者的系统环境为windows8.1&x64. 安装 ...

  4. 0.[Andriod]之从零安装配置Android Studio并编写第一个Android App

    0. 所需的安装文件 笔者做了几年WP,近来对Android有点兴趣,尝试一下Android开发,废话不多说,直接进入主题,先安装开发环境,笔者的系统环境为windows8.1&x64. 安装 ...

  5. 篇一、安装配置Android Studio

    系统:Mac 10.10 Java JDK:官方JDK1.8 IDE:Android Studio 1.2 Android SDK:24.2 模拟器:genymtion 安装 Mac版本的Androi ...

  6. [Android] 环境优化配置Android Studio发展NDK

    ======================================================== 作者:qiujuer 博客:blog.csdn.net/qiujuer 站点:www. ...

  7. 安装Android Studio (一)同时配置Android Studio环境变量

    安装Android Studio 安装android 一直next就行了.这以步需要10分钟左右. 我的安卓SDK在这个目录 C:\Users\user\AppData\Local\Android\s ...

  8. 配置Android Studio

    1.去gradle官网下载gradle,gradle的版本可以在C:\Program Files\Android\Android Studio\gradle下看到 2.新建一个项目,退出后把下载好的g ...

  9. ubuntu14.04 配置android studio环境

    二.复制所需的文件到ubuntu 2.1.如果你还没有linux版本的android studio.sdk.jdk请先下载所需文件,我已经上传到百度网盘了 下载地址: android studio-l ...

随机推荐

  1. Pig 实现关键词匹配

    1. 问题描述 收集日志avro数据中有两个Map字段appInstall.appUse分别表示已安装的app.正在使用的app,且key值为app的名称,value值为app使用信息.现在要得到一份 ...

  2. Javascript动画效果(四)

    Javascript动画效果(四) 前面我们自己写了一个小小的关于js动画的插件,下面我们来使用之前的框架来完成我们想要的动画效果.我们经常在淘宝网中看到,鼠标经过某一图片时,该图片有从上滚出而又从下 ...

  3. 【Swift学习】Swift编程之旅---扩展(二十四)

    扩展就是向一个已有的类.结构体或枚举类型添加新功能,包含属性和方法,如果你定义了一个扩展向一个已有类型添加新功能,那么这个新功能对该类型的所有已有实例中都是可用的,即使它们是在你的这个扩展的前面定义的 ...

  4. 【Swift学习】Swift编程之旅(三)

    元组(tuples) tuples是将多个单一的值组合为一个复合的值.它可以包含任何类型的值,而不需要都是相同类型. 一.元组的创建 1. let http404error = (,"NOT ...

  5. noip 模拟赛 匹配 //贪婪策略

    匹配(match.pas/match.c/match.cpp) [题目描述] 到了新的学期,Mcx痛苦的发现通用技术课居然是有实验课的,这样的话他就不得不放弃写作业的想法而去做一件类似于搭积木的事情. ...

  6. Log4net 日志使用介绍

    概述 Log4net 有三个主要组件:loggers,appenders 和 layouts.这三个组件一起工作使得开发者能够根据信息类型和等级(Level)记录信息,以及在运行时控制信息的格式化和信 ...

  7. ASP.NET MVC系列:添加视图

    虽然在上一篇文章中我们知道通过控制器可以在浏览器输出HTML页面,但是这不是控制器主要干的事,因为页面上我为还要做很多好看的特效,页面展示的事情当然交给视图来做了:下面我们就来看看如何添加一个视图 添 ...

  8. 重构:用Command替换条件调度程序

    注:该随笔受启发于 <重构与模式>  第七章 第7.6小节 用Command替换条件调度程序 . 对于Command不做过多解释,这里我找了两个例子.供部分园友参阅:Command例子1  ...

  9. 【UWP】在不同类库使用ResourceDictionaries

    通常我们在类库中定义资源的时候可以在Theme/Generic.xaml中定义,当类库加载的时候,会自动加载Generic.xaml文件中的资源,通常用在控件库中,但如果控件多了之后,所有的Style ...

  10. ASP.NET MVC 模块与组件(二)——定制图片验证码

     本着简洁直接,我们就直奔主题吧! 下面是一个生成数字和字母随机组合的验证码类源代码: using System; using System.Drawing; using System.Drawing ...