开始学excilys/androidannotations

//2016-04-26 00:50

android studio上gradle配置

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

APP的gradle:

apply plugin: 'com.android.application'
apply plugin: 'android-apt'//这里
def AAVersion = 'XXX'//这里
dependencies {//原本还会有其他内容,在后面直接添加下面两句即可
    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}
//下面的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 should set your package name here if you are using different application IDs
        // resourcePackageName "your.package.name"

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

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 23
    }
}
project的gradle:

buildscript {
    repositories {
      mavenCentral()
    }
    dependencies {
        // replace with the current version of the Android plugin
        classpath 'com.android.tools.build:gradle:1.5.0'
        // replace with the current version of the android-apt plugin
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'//添加这句即可
    }
}

自定义注释

如果你有一些特殊的应用案例,那么你就可能需要自定义注释。为此,你可以在你的配置中声明options。(如何根据环境配置请详见下面)。

原文:https://github.com/excilys/androidannotations/wiki/CustomizeAnnotationProcessing

翻译:

可用的options

Trace

类型:boolean

trace常用语启用或禁用@Trace注释。通过这一注释跟踪方法的执行,并显示在log条目上。

androidManifestFile

类型:string,path

默认情况下,AndroidAnnotations会在父目录中递归查找AndroidManifest.xml。在project结构特殊的情况下,你可以为androidManifestFile option(其实就是配置androidManifestFile)制定路径。

resourcePackageName

类型:String

默认情况下,AndroidAnnotations会在AndroidManifest中获取包名,用于查找R类。但某些情况下,你可能希望指定一个自定义包的路径,用于查找R类。这就是我们添加resourcePackageName option的原因

logFile

logLevel

类型:string, enum(trace, debug, info, warn, error)

默认为warn,出现问题时,设置为trace不失为一大助力。

logAppenderConsole

logAppenderFile

threadControl

classSuffix

类型:String

用于决定使用annotation编写的类产生的新类的类名后缀,默认值是_。比如,原本是A.class,会产生一个A_.class

generateFinalClasses

类型:boolean

设置新产生的类是否final类,默认为true

library

类型:boolean

表示此project是否为library,默认为false

encoding

控制生成源文件时的编码,默认为UTF-8。只能指定Charset.forName()能接受的编码。

How to use options

apt {
    arguments {
        // you can set annotation processing options here
        logLevel 'TRACE'
        logAppenderConsole 'true'
    }
}

//


To be continue...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值