转: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文件分析等,方便开发人员自测或者测 ...
随机推荐
- word安装楷体gb2312方法。
1:下载:楷体gb2312.http://www.downza.cn/soft/7732.html 2: 双击安装,将会下载楷体2312 的压缩文件,解压得到楷体2312.ttf. 3: 打开控制 ...
- PAT 1137 Final Grading[一般][排序]
1137 Final Grading(25 分) For a student taking the online course "Data Structures" on China ...
- 如何确定selenium ID元素是否查找正确
编写脚本时,如何确定通过id查找的id是否真实存在,点击css,然后输入#(代表id)id名,如#kd,回车之后,能返回结果,便代表存在.
- 右值引用与转移语义(C++11)
参考资料: http://www.cnblogs.com/lebronjames/p/3614773.html 左值和右值定义: C++( 包括 C) 中所有的表达式和变量要么是左值,要么是右值.通俗 ...
- Linux安装rpm包时报错Header V3 DSA/SHA1 Signature, key ID 1d1e034b: NOKEY解决办法
这是因为yum安装了旧版本的GPG key造成的,解决办法: rpm --import /etc/pki/rpm-gpg/RPM* Header V3 DSA/SHA1 Signature, key ...
- STL学习笔记--各种容器的运用时机
如何选择最佳的容器类别? 缺省情况下应该使用vector.vector的内部结构简单,并允许随机存取,所以数据的存取十分方便灵活,数据的处理也够快. 如果经常要在序列的头部和尾部安插和移除元素,应采用 ...
- 141. Linked List Cycle(判断链表是否有环)
141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can you sol ...
- 居于mtk芯片安卓车机系统具体流程
一:车机系统框架 MCU 功能 电源控制 Radio 控制(RDS) 按键检测(Panel/Remote/SW) 常见信号检查(倒车/大灯/刹车) CAN 模块通讯 ARM- ...
- LabView和DLL中的参数问题
注意:在LabView中调用DLL函数时,一定要指定对应的参数类型,而不是选择“Adapt to Type”,否则会出错,不知道为什么书上是要选择“Adapt to Type”. 以下做个参考: 转自 ...
- 20145329 《网络对抗技术》PC平台逆向破解
shellcode注入 实践是在非常简单的一个预设条件下完成的: (1)关闭堆栈保护 (2)关闭堆栈执行保护 (3)关闭地址随机化 (4)在x32环境下 (5)在Linux实践环境 shellcode ...