转: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. @

晚点送上翻译(渣翻)

时间: 2024-08-23 04:20:01

转:Android-apt的相关文章

Android APT

APT APT(Annotation Processing Tool)是一种处理注释的工具,它对源代码文件进行检测找出其中的Annotation,使用Annotation进行额外的处理. Annotation处理器在处理Annotation时可以根据源文件中的Annotation生成额外的源文件和其它的文件(文件具体内容由Annotation处理器的编写者决定),APT还会编译生成的源文件和原来的源文件,将它们一起生成class文件. 作者:技术萌新 链接:https://www.jianshu

你必须知道的APT、annotationProcessor、android-apt、Provided、自定义注解

你可能经常在build.gradle文件中看到,这样的字眼,annotationProcessor.android-apt.Provided,它们到底有什么作用?下面就一起来看看吧 1.什么是APT? 随着一些如ButterKnife,dagger等的开源注解框架的流行,APT的概念也越来越被熟知. annotationProcessor和android-apt的功能是一样的,它们是替代关系,在认识它们之前,先来看看APT. APT(Annotation Processing Tool)是一种处

Android性能测试工具之APT

1.APT工具简介: APT是一个eclipse插件,可以实时监控Android手机上多个应用的CPU.内存数据曲线,并保存数据:另外还支持自动获取内存快照.PMAP文件分析等,方便开发人员自测或者测试人员完成性能测试,快速发现产品问题.项目地址:https://code.csdn.net/Tencent/apt 2.APT的功能 支持多进程的CPU测试,并提供top和dumpsys cpuinfo两种方式. 支持多进程的内存测试,并支持9种内存类型,测试过程中可动态调整要显示的内存类型曲线.

【Android性能工具】腾讯开源工具APT

做App测试时监测使用期间的cpu,内存,流量,电量等指标时,发现的企鹅很好用的工具. 备份至此,方便后期查阅 转载自CSDN的文章:[腾讯开源]Android性能测试工具APT使用指南 原文URL http://www.csdn.net/article/2014-04-23/2819366-tencent-APT-open-source-tool-guide APT提供了CPU利用率实时曲线图.多维度内存实时曲线图,方便竞品对比测试和定位内存泄露问题:支持进程内存构成分析,支持手工或超过阈值时

【腾讯开源】Android性能测试工具APT使用指南

[腾讯开源]Android性能测试工具APT使用指南 2014-04-23 09:58 CSDN CODE 作者 CSDN CODE 17 7833 腾讯 apt 安卓 性能测试 开源 我们近日对腾讯的安卓平台高效的性能测试工具APT团队进行了专访.APT,适用于开发自测和定位性能瓶颈,帮助完成性能基准测试.竞品测试.我们为大家准备了从安装部署到开启APT各功能的介绍资料,方便大家参考. 我们近日对腾讯的安卓平台高效的性能测试工具APT团队进行了专访.APT,Android Performanc

Android性能测试工具APT使用指南

腾讯的安卓平台高效的性能测试工具APT(Android Performance Testing Tools),适用于开发自测和定位性能瓶颈,帮助测试人员完成性能基准测试.竞品测试. APT提供了CPU利用率实时曲线图.多维度内存实时曲线图,方便竞品对比测试和定位内存泄露问题:支持进程内存构成分析,支持手工或超过阈值时自动转储(Dump)详细堆内存对象信息,支持多进程,支持生成和导出常用格式的的日志图表. APT相比同类工具,具有下面2大特性: 使用Java语言开发,基于Eclipse,跨平台,支

使用APT测试Android应用性能

一.APT介绍: APT:Android Performance Testing Tools,适用于开发自测和定位性能瓶颈,帮助测试人员完成[性能基准测试.竞品测试]. APT提供了CPU利用率实时曲线图.多维度内存实时曲线图,方便竞品对比测试和定位内存泄露问题:支持进程内存构成分析,支持手工或超过阈值时自动转储(Dump)详细堆内存对象信息,支持多进程,支持生成和导出常用格式的的日志图表. APT相比同类工具,具有下面2大特性: ①.使用Java语言开发,基于Eclipse,跨平台,支持win

android注解处理技术APT

APT(Annotation Processing Tool)是java的注解处理技术,它对源代码文件进行检测找出其中的Annotation,根据注解和注解处理器和相应的apt自动生成代码. Annotation处理器在处理Annotation时可以根据源文件中的Annotation生成额外的源文件和其它的文件(文件具体内容由Annotation处理器的编写者决定). 1.什么是APT? android-apt和annotationProcessor功能是一样的,都是apt的实现,前者比较早,后

使用APT实现Android中View的注入

个人博客 http://www.milovetingting.cn 使用APT实现Android中View的注入 前言 APT是Annotation Processing Tool的简写,通过在Java编译时期,处理注解,生成代码.APT在ButterKnife.Dagger2等框架中都有应用.下面通过使用APT,实现一个类似ButterKnife的简单的View注入的框架.(参考Jett老师的课程) ButterKnife的实现原理 既然准备实现类似ButterKnife的框架,那么我们就需要

Android换肤技术总结

原文出处: http://blog.zhaiyifan.cn/2015/09/10/Android%E6%8D%A2%E8%82%A4%E6%8A%80%E6%9C%AF%E6%80%BB%E7%BB%93/ 背景 纵观现在各种Android app,其换肤需求可以归为 白天/黑夜主题切换(或者别的名字,通常2套),如同花顺/自选股/天天动听等,UI表现为一个switcher. 多种主题切换,通常为会员特权,如QQ/QQ空间. 对于第一种来说,目测应该是直接通过本地theme来做的,即所有图片/