android studio annotation 配置过程

参考了好些配置,发现总有这样,那样的问题。

环境:androidstudio 1.5 preview 2 sdk 6.0

1.首先新建一个android项目。

过程略

2.配置project的build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath ‘com.android.tools.build:gradle:1.3.0‘

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath ‘com.neenbedankt.gradle.plugins:android-apt:1.4+‘
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

其中红色为添加的部分,主要是使用apt插件。

3.配置module的build.gradle

apply plugin: ‘com.android.application‘
apply plugin: ‘android-apt‘
def AAVersion = ‘3.2+‘
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.joyfulmath.myannnotationsample"
        minSdkVersion 21
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘
        }
    }
}

/**
 * AA注解Apt配置
 */
apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        // if you have multiple outputs (when using splits), you may want to have other index than 0

        // You can set optional annotation processing options here, like these commented options:
        // logLevel ‘INFO‘
        // logFile ‘/var/log/aa.log‘

    }
}

dependencies {
    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
    testCompile ‘junit:junit:4.12‘
    compile ‘com.android.support:appcompat-v7:23.1.0‘
}  

红色为添加部分。

编译后,按理就可以使用annotation了。

4.使用annotation

可以百度下。

5.常见问题

错误: Could not find the AndroidManifest.xml file, going up from path

/**
 * AA注解Apt配置
 */
apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        // if you have multiple outputs (when using splits), you may want to have other index than 0

        // You can set optional annotation processing options here, like these commented options:
        // logLevel ‘INFO‘
        // logFile ‘/var/log/aa.log‘

    }
}

如果在module下的build.gradle没有配置,就会有这个问题。

参考文档:

http://blog.csdn.net/caiwenfeng_for_23/article/details/45801151

http://apkdemo.com/gradle/

http://blog.csdn.net/wa991830558/article/details/41647781

https://github.com/excilys/androidannotations/wiki/Building-Project-Gradle

时间: 2024-07-31 00:26:33

android studio annotation 配置过程的相关文章

android studio+grade配置构建

Android 构建系统编译应用资源和源代码,然后将它们打包成可供您测试.部署.签署和分发的 APK.android Studio 使用 Gradle 这一高级构建工具包来自动化执行和管理构建流程,同时也允许您定义灵活的自定义构建配置.每个构建配置均可自行定义一组代码和资源,同时对所有应用版本共有的部分加以重复利用.Android Plugin for Gradle 与这个构建工具包协作,共同提供专用于构建和测试 Android 应用的流程和可配置设置. Gradle 和 Android 插件独

Android Studio最新配置教程2016

http://blog.csdn.net/wen_demo 一.Android studio 基本简单介绍 1.Android studio和Eclipse的差别: 1.Studio中有Project和Module的概念,Studio中一个窗体仅仅能有一个项目,即Project,代表一个workspace.可是一个Project能够包括多个Module.比方你项目引用的Android Library, Java Library等,这些都能够看做是一个Module. 2.文件夹中将java代码和资

Android Studio安装配置详细步骤(图文)

Android studio 教程 为什么要使用Android Studio Android Studio是谷歌推出了新的Android开发环境,其重要性可想而知! 1. 集成了Gradle 打包工具 2. 所见即所得的效果 3. 可拖拽的UI操作 4. 代码自动补全 5. 更多的操作接口 6. Google Cloud的集成 7. 全新的JUnit 8. Maven仓库的集成 下载 到 https://developer.android.com/sdk/index.html (需翻墙)或者ht

Android Studio最新配置教程2015

http://blog.csdn.net/wen_demo 一.Android studio 基本简介 1.Android studio和Eclipse的区别: 1.Studio中有Project和Module的概念,Studio中一个窗口只能有一个项目,即Project,代表一个workspace,但是一个Project可以包含多个Module,比如你项目引用的Android Library, Java Library等,这些都可以看做是一个Module. 2.目录中将java代码和资源文件(

Android学习及开发随记1:Android Studio安装配置

1.本系列仅为个人使用,概不负责.随着时间推移,部分内容可能因为软件更新而出现不能对应的情况. 本文的配置情况,仅针对Android Studio v1.1.0 windows版本 全新安装. Google Android Developers Site:https://developer.android.com/sdk/index.html The official Android IDE:https://dl.google.com/dl/android/studio/install/1.1.

关于android studio的配置JAVA_HOME的问题

关于Android Studio的配置JAVA_HOME的问题 在配置环境变量时,我们一般配置JAVA_HOME的目录值为 C:\Program Files\Java\jdk1.8.0_45\bin 但是我们在打开Android Studio的时候会出现问题,无法打开,提示找不到对应的JVM,此时,我们只需要将值改为 C:\Program Files\Java\jdk1.8.0_45 即可,可能程序会自动去默认的bin目录中寻找相应的程序,因此,以后我们将JAVA_HOME的值配置为上述即可.

在ADT和Android Studio中配置和使用Git

株洲新程IT教育 李赞红 搞了半天,图片居然没上传,直接下载吧:http://download.csdn.net/detail/lifenote/9500827 1.版本控制的作用 A.版本控制 B.项目的基本管理 C.团队协作开发 D.历史记录 E.文件跟踪 2.两个常用的GIT服务商 A.国外:github   https://github.com/ B.国内:[email protected]  http://git.oschina.net/(本文使用这个) 3.GIT的工作原理 A.数据

Android Studio安装配置

Android Studio安装配置: 1.Android Studio可以在官网上下载,由于懒得原因,我直接在百度中心下载. 下载地址:http://rj.baidu.com/soft/detail/27390.html?ald 2.本机系统为window 8 64位,因此,Android Studio默认为64位,由于原有的开发环境JDK1.7是32位的,因此,需要做以下步骤: a.下载安装JDK64位. b.将JDK环境变量指向64位的JDK,并在path中将JDK配置移动到最前位置. c

Android Studio如何配置CURL指令一键打包apk上传至蒲公英

Android Studio如何配置CURL指令一键打包apk上传至蒲公英 第一步:在所需要打包的模块build.gradle文件中加入如下代码: android{ buildTypes { //配置apk名称 android.applicationVariants.all { variant -> variant.outputs.all { outputFileName = getApkName() } } } } android{ } //------------以下代码用于配置一键上传蒲公