转:Android-apt
转自http://blog.csdn.net/zjbpku/article/details/22976291
What is this?
The Android-apt plugin assists in working with annotation processors in combination with Android Studio. It has two purposes:
- Allow to configure a compile time only annotation processor as a dependency, not including the artifact in the final APK or library
- Set up the source paths so that code that is generated from the annotation processor is correctly picked up by Android Studio.
This plugin requires the android or android-library plugin (version 0.7.x or up) to be configured on your project.
Including and using the plugin in your build script
Add the following to your build script to use the plugin:
buildscript { repositories { mavenCentral() }
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:0.7.3'
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2' }
}
apply plugin: 'android'apply plugin: 'android-apt'
Passing processor arguments
Some annotation processor may require to pass custom arguments, you can use apt.argumentsfor that purpose. For instance Android Annotation library needs the following configuration:
apt { arguments { resourcePackageName android.defaultConfig.packageName androidManifestFile variant.processResources.manifestFile }}
Make sure to configure packageName in the android defaultConfig block for this purpose. The arguments are processed for each variant when the compiler is configured. From this closure you can reference android, project and variant for the current variant.
Configurating a compiler style dependency
Annotation processors generally have a API and a processor that generates code that is used by the API. Depending on the project the processor and the API might be split up in separate dependencies. For example,Dagger uses two artifacts called dagger-compiler and dagger. The compiler artifact is only used during compilation, while the main dagger artifact is required at runtime.
To aid in configuring this dependency, the plugin adds a Gradle configuration named apt that can be used like this:
dependencies { apt 'com.squareup.dagger:dagger-compiler:1.1.0' compile 'com.squareup.dagger:dagger:1.1.0'}
Configuration of other annotation processors
For annotation processors that include the API and processor in one artifact, there's no special setup. You just add the artifact to the compile configuration like usual and everything will work like normal. Additionally, if code that is generated by the processor is to be referenced in your own code, Android Studio will now correctly reference that code and resolve references to it.
History & Credits
This plugin is based on a script that I've been using for some time which is the result of this post on Google+ and this post on StackOverflow.com. Variations of the SO post and my gists have been floating around for a while on the interwebs. That, and the fact that including scripts is a bit inconvenient pushed me to create this plugin.
License
This plugin is created by Hugo Visser and released in the public domain. Feel free to use and adapt as you like. To get in touch, hit me up onTwitter orGoogle Plus. @
晚点送上翻译(渣翻)
转:Android-apt的更多相关文章
- Android APT(编译时代码生成)最佳实践
越来越多第三方库使用apt技术,如DBflow.Dagger2.ButterKnife.ActivityRouter.AptPreferences.在编译时根据Annotation生成了相关的代码,非 ...
- Android APT
APT APT(Annotation Processing Tool)是一种处理注释的工具,它对源代码文件进行检测找出其中的Annotation,使用Annotation进行额外的处理. Annota ...
- 搭建一个完整的Android工程(一)Dagger2
写在前面 现在越来越多的使用到了开源项目,但是仅限于使用,却不了解,更谈不上深入.也是因为越来越多的开源项目,平时工作中遇到问题也是第一时间寻找对应的开源项目,少了许多独立的思考.现在虽然能很轻松的完 ...
- AS 注解处理器 APT Processor MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Android性能测试工具APT使用指南
腾讯的安卓平台高效的性能测试工具APT(Android Performance Testing Tools),适用于开发自测和定位性能瓶颈,帮助测试人员完成性能基准测试.竞品测试. APT提供了CPU ...
- Android客户端性能测试(一):使用APT测试Android应用性能
一.APT介绍: APT:Android Performance Testing Tools,适用于开发自测和定位性能瓶颈,帮助测试人员完成[性能基准测试.竞品测试]. APT提供了CPU利用率实时曲 ...
- 基于apt实现的Android快速持久化框架:AptPreferences
AptPreferences是基于面向对象设计的快速持久化框架,目的是为了简化SharePreferences的使用,减少代码的编写.可以非常快速地保存基本类型和对象.AptPreferences是基 ...
- 【腾讯开源】Android性能测试工具APT使用指南
[腾讯开源]Android性能测试工具APT使用指南 2014-04-23 09:58 CSDN CODE 作者 CSDN CODE 17 7833 腾讯 apt 安卓 性能测试 开源 我们近日对腾讯 ...
- android注解处理技术APT
APT(Annotation Processing Tool)是java的注解处理技术,它对源代码文件进行检测找出其中的Annotation,根据注解和注解处理器和相应的apt自动生成代码. Anno ...
- Android性能测试工具之APT
1.APT工具简介: APT是一个eclipse插件,可以实时监控Android手机上多个应用的CPU.内存数据曲线,并保存数据:另外还支持自动获取内存快照.PMAP文件分析等,方便开发人员自测或者测 ...
随机推荐
- Cardano(ADA), EOS, RChain(RHOC), Aeternity(AE) 都是极其好的币
从区块链的基础知识出发,研究ETH和EOS的区别 免责声明:EOS目前还在开发中,我们对此项目的一些理解可能会改变.而且,我并不是以太坊开发者,而只是一个喜欢区块链的爱好者.请牢记这两点,请把下面的内 ...
- 单台DNS服务器搭建(BIND)
一.理论层面 1. DNS的出现及演化 网络出现的早期是使用IP地址通讯的,那是就几台主机通讯.但是随着接入网络主机的增多,这种数字标识的地址非常不便于记忆,UNIX上就出现了建立一个叫做hosts的 ...
- [环境配置] 如何为Apache绑定多IP多域名
在Apache服务器上绑定方法比较简单,主要因为Apache是个开源独立的服务器软件,而且支持跨平台安装和配置,支持丰富的API扩展,所以很多人对Apache的好感要甚于IIS,Apache的优点就不 ...
- extern--C#调用C++等其他非托管代码
例如: https://www.cnblogs.com/sosoft/p/extern.html
- LINUX实践--程序破解
实验思想 本次实验的主要思想有两个,第一个是修改跳转指令,把它变成无条件跳转使得无论输入什么用户名都跳转到失败的那个选项中去,第二个思想是修改比对的内容,即不判断条件,从而成功 实验步骤 1.首先从老 ...
- double、float等多字节数据处理
一.常规的多字节: 有2,4,8字节 float和double是具有自身算法的数据类型,和其他整型不一样[整型数据,可以直接通过移位来进行计算值的大小,float和double不行] 值 = 尾数x ...
- [BZOJ1176]Mokia
Description 维护一个W*W的矩阵,初始值均为S.每次操作可以增加某格子的权值,或询问某子矩阵的总权值.修改操作数M<=160000,询问数Q<=10000,W<=2000 ...
- Tensorflow1.5.0+cuda9.0+cudnn7.0+gtx1080+ubuntu16.04
目录 Tensorflow1.5.0+cuda9.0+cudnn7.0+gtx1080+ubuntu16.04 0. 前记 1. 环境说明 2. 安装GTX1080显卡驱动 3. CUDA 9.0安装 ...
- UVa 10943 全加和
https://vjudge.net/problem/UVA-10943 题意: 把K个不超过N的非负整数加起来,使得它们的和为N,有多少种方法? 思路: d[i][j]表示用i个数加起来为j的方法数 ...
- python fromkeys() 创建字典
# d = dict.fromkeys("张无忌","赵敏") #创建字典 # print(d)#{'张': '赵敏', '无': '赵敏', '忌': '赵敏 ...